Reputation: 108
This code works well and I am receiving data from server. Data consists of [{id: someId, name: someName}, {..}....{...}]
SJA.ajax(dataToSend, function (respond) {
if (respond) {
for (var i in respond) {
console.log(respond[i].id);
console.log(respond[i].name);
}
}
});
How can I create an array from only respond[i].name
and use this array in such a way:
var data = ["name", "name", "name"];
Upvotes: 0
Views: 54
Reputation: 168843
Simply
var names = respond.map(function(r) { return r.name; });
will do what you want.
Upvotes: 2