场景:

我需要数组中每个对象的相同属性。

示例:fiddle

var texts = [];
var arr = [{text:"first"}, {text:"second"}]
arr.forEach(item => {
    texts.push(item.text);
});
console.log(text); // >(2) [ "first", "second" ]


题:

是否有此概念的“简写”版本?

例如。 arr.childPropFilter("text")

最佳答案

使用map()返回基于迭代原始数组的新数组

var texts = arr.map(o => o.text)

关于javascript - 对象数组属性提取循环速记,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45082458/

10-12 00:14
查看更多