Your inquiry is somewhat unclear, but the following code may provide a starting point to help you achieve your objective.
Utilizing the forEach
function can easily assist in this task.
var ids = [];
var names = [];
data.forEach(function(obj) {
ids.push(obj.id);
names.push(obj.name);
});
If you also wish to utilize the map
function
var ids = data.map(function(obj){
return obj.id;
});
var names = data.map(function(obj){
return obj.name;
});
However, if cross compatibility is crucial, consider employing a standard for
loop.
var ids = [];
var names = [];
for (var i in data) {
ids.push(data[i].id);
names.push(data[i].name);
}
Expected Output
["1", "2", "3", "4", "5"] // ids
["name1", "name2", "name3", "name4", "name5"] // names