Henriques Henriques - 4 months ago 9
AngularJS Question

Push the values in to an array using AngularJS

my service returns data from DB, now i want to push particular values from that data in to an array using AngularJS.

var prodData = make a call to the service.

var versionsArray = [];


The data returned from the service looks similar format

{"prodId":"31123","prodName":"IPhone","Versions":[4,5,6]}


Now I want to push the values of the field "Versions":[4,5,6] in to an array called
versionsArray
, so that later I can bind that array to a drop-down and display the versions in the drop-down.

I wanted to something in the below way

Versions.push({
id: prodData.Versions,
value: prodData.Versions
});


How do I retrieve those values an push them in to an array ?

Answer

well, Here how you can do it,

angular.forEach(prodData.Versions, function(version) {
    versionsArray.push(version);
});

I hope it helps you.

Cheers!