对象的不同数组,如下所示;我想得到唯一的对象数组。
阵列示例:
const data = [ { "name": "abc", age: "31", project: "Java" }, { "name": "abc", age: "31", project: "Java" }, { "name": "abc", age: "29", project: "Javascript" }, { "name": "abc", age: "31", project: "C++" }, { "name": "abc", age: "31", project: "Java" }, { "name": "abc", age: "31", project: "Java" }]
预期输出:
const data = [ { "name": "abc", age: "31", project: "Java" },{ "name": "abc", age: "29", project: "Javascript" }, { "name": "abc", age: "31", project: "C++" }]
3条答案
按热度按时间5gfr0r5j1#
0wi1tuuw2#
这种方法强制执行一致的键顺序,并在每个对象上使用JSON.stringify来测试唯一性。
pdkcd3nj3#
根据您的数据,
project
属性包含动态值。因此,您可以使用Array.filter()
方法在单行代码中过滤出重复的值。现场演示**:**