Is there any tool to to create:
[ 'John', 'Sam', 'Marry' ]
from:
[ { name: 'John' }, { name: 'Sam' }, { name: 'Marry' } ]
?
Yeah, the map()
method:
var array = [{name: 'John'}, {name: 'Sam'}, {name: 'Mary'}].map(function (val) {
return val.name;
});
or jQuery's version:
var array = jQuery.map([{name: 'John'}, {name: 'Sam'}, {name: 'Mary'}], function (val) {
return val.name;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With