javascript Javascript - 仅返回对象数组中的唯一值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Javascript - 仅返回对象数组中的唯一值相关的知识,希望对你有一定的参考价值。
const data = [
{
"objectId": "WMtwbyhFI6",
"cuisineNameEn": "Cafe",
"ordersNo": 20,
"hidden": false
},
{
"objectId": "QJSNTMpq5F",
"ordersNo": 24,
"cuisineNameEn": "Italian",
"hidden": false
},
{
"objectId": "iLXKswFRGa",
"ordersNo": 5,
"cuisineNameEn": "Japanese",
"hidden": true
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
},
{
"objectId": "QJSNTMpq5F",
"ordersNo": 24,
"cuisineNameEn": "Italian",
"hidden": false
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false,
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
},
{
"objectId": "Db0MeihpJE",
"ordersNo": 6,
"cuisineNameEn": "Fast Food",
"hidden": false
}
];
console.log(data.reduce((acc, x) =>
acc.concat(acc.find(y => y.ordersNo === x.ordersNo) ? [] : [x])
, []));
以上是关于javascript Javascript - 仅返回对象数组中的唯一值的主要内容,如果未能解决你的问题,请参考以下文章
javascript JavaScript isset()等效: - JavaScript
JavaScript 使用JavaScript更改CSS(JavaScript)
JavaScript之基础-1 JavaScript(概述基础语法)
前端基础-JavaScript的基本概述和语法
JavaScript
JavaScript