Convert array of objects into array of properties
A more minimal example (ES6 onwards):
someJsonArray.map(({id}) => id)
You could do something like this:
var len = someJsonArray.length, output = [];
for(var i = 0; i < len; i++){
output.push(someJsonArray[i].id)
}
console.log(output);
You can do this way:
var arr = [];
for(var i=0; i<someJsonArray.length; i++) {
arr.push(someJsonArray[i].id);
}
Use .map()
function:
finalArray = someJsonArray.map(function (obj) {
return obj.id;
});
Snippet
var someJsonArray = [
{id: 0, name: "name", property: "value", therproperties: "othervalues"},
{id: 1, name: "name1", property: "value1", otherproperties: "othervalues1"},
{id: 2, name: "name2", property: "value2", otherproperties: "othervalues2"}
];
var finalArray = someJsonArray.map(function (obj) {
return obj.id;
});
console.log(finalArray);
The above snippet is changed to make it work.