from this array:
var arr = [
{
element: 'anything',
order: 1
},
{
element: 'something',
order: 2
}
]
I want to generate this:
arr = ['anything', 'something'];
How to do this?
Use the map function
var arr2 = arr.map(x => x.element);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
arr.map(x => x.element) ;)You can use vanilla js: as shown by @James L.:
arr.map(x => x.element);
or use jQuery Map function:
$.map(arr, function(val, i){
return val.element;
})
See Docs: http://api.jquery.com/jQuery.map/