小编her*_*erm的帖子

对象数组中Array中不同的值

香港专业教育学院有一系列的对象。每个对象内都有另一个数组。我想从这些数组中提取不同的值。

var data = [
            {categorie: 'Stuff', type: 'One', designs: ['A', 'B']},
            {categorie: 'Stuff', type: 'Two', designs: ['C']},
            {categorie: 'Stuff', type: 'One', designs: ['D']},
            {categorie: 'Other', type: 'Three', designs: ['C', 'D']}
        ];
console.log([...new Set(data.map(x => x.categorie))]);
console.log([...new Set(data.map(x => x.type))]);

//expected output for designs ['A','B','C','D']
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
59
查看次数

标签 统计

javascript ×1