Igor Simic
8 years ago

How to push data in javascript object


How to add new items to javascript object, or how to push data in JS object:

<script>
var defaultTags = [];
      
      //loop the object $scope.editContent.tags
      angular.forEach($scope.editContent.tags, function(value, key) {
                
                // create new object with some data for every loop
                var newObject = {};
                   
                  newObject["id"] = 1;
                  newObject.id = value.hashid;

                  newObject["name"] = 1;
                  newObject.name = value.tags;
              this.push(newObject);
      
      }, defaultTags);
 
      $scope.selectedTags = defaultTags
</script>