有没有一种简单的方法,使用filter
或parse
或其他方式来转换如下的数组:
var someJsonArray = [
{id: 0, name: "name", property: "value", otherproperties: "othervalues"},
{id: 1, name: "name1", property: "value1", otherproperties: "othervalues1"},
{id: 2, name: "name2", property: "value2", otherproperties: "othervalues2"}
];
将前一个数组中包含的对象的一个属性填充到一个简单的数组中,就像这样:
[0, 1, 2]
someJsonArray.map(function(o) { return o.id; })
是什么意思?关于 map 的文档 - tforgioneArray.from(arrayLike, x => x.foo)
。 - TechWisdom