userpr
userpr

Reputation: 213

Push object with angular foreach

I have a data type object like this :

["Tag Name13", "Tag Name12"]

But if i push with this script :

var list_tag = [];

angular.forEach(retrive_data.tags, function(item){
   list_tag.push(item.label);
});

$scope.tag = list_tag;

The output in console.log is

[Object, Object, Object]

And I open the structure like this :

Array[3]
0
:
Object
1
:
Object
2
:
Object

Yes, my data has pushed but data the structure is changed and i can't process in the next step. am I wrong ? give me solution please , Thanks

UPDATED

Array[2]
0 : "Tag Name13"
1 : "Tag Name12"

UPDATED

Array[2]

_id:"58a28112a6551f5b8a4fc0d3"
active:0
created_at:"2017-02-14 11:01:22"
description:"Lorem ipsum dolor sit amet, consectetur adipisci13"
image:"http://placehold.it/300x30013"
label:"Tag Name13"
meta_description:"Meta Description Tag Name13"
meta_keyword:"Meta Keywoprd Tag Name13"
meta_title:"Meta Title Tag Name13"
priority:100
related:"[]"
thread_count:0
thread_ids:Array[1]
updated_at:"2017-03-03 11:53:20"
url:"tag-name13"

Upvotes: 1

Views: 7184

Answers (2)

Gaurav Kumar Singh
Gaurav Kumar Singh

Reputation: 1570

first of all you need to take another variable just use scope variable only

Check my code

$scope.tags = [];

angular.forEach(retrive_data.tags, function(item){
   $scope.tags.push(item.label);
});

console.log($scope.tags) //output ["Tag Name13", "Tag Name12"]

Upvotes: 1

Ashish Yadav
Ashish Yadav

Reputation: 350

 var list_tag = [];

 angular.forEach(retrive_data.tags, function(item){
  list_tag.push(item);
});

$scope.tag = list_tag;

I think its should be like above

Upvotes: 0

Related Questions