如果你的对象数组是 items,你可以:

var items = [{
id: 1,
name: 'john'
}, {
id: 2,
name: 'jane'
}, {
id: 2000,
name: 'zack'
}];


var names = items.map(function(item) {
return item['name'];
});


console.log(names);
console.log(items);

文件: < a href = “ https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global _ Objects/Array/map”rel = “ noReferrer”> map()

使用 JavaScript 数组中原生的 map()函数:

var yourArray = [ {
'id':1,
'name':'john'
},{
'id':2,
'name':'jane'
}........,{
'id':2000,
'name':'zack'
}];


var newArray = yourArray.map( function( el ){
return el.name;
});

你可以使用这个函数:

function createStringArray(arr, prop) {
var result = [];
for (var i = 0; i < arr.length; i += 1) {
result.push(arr[i][prop]);
}
return result;
}

只需传递对象数组和您需要的属性。 上面的脚本甚至可以在老的 EcmaScript 实现中工作。

You can do this to only monitor own properties of the object:

var arr = [];


for (var key in p) {
if (p.hasOwnProperty(key)) {
arr.push(p[key]);
}
}