What is the equivalent to PHP\'s array_column()
in jQuery? I need the data inside the array without looping, in the same way as in PHP.
You can do it with .map(). Immagine a fetch of database rows.
var array = [
{
id: 1,
name: 'foo'
},
{
id: 2,
name: 'bar'
},
];
var names = arrayColumn(array, 'name');
console.log(names);
function arrayColumn(array, columnName) {
return array.map(function(value,index) {
return value[columnName];
})
}