数组对象 级别 交集
Posted nns4
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组对象 级别 交集相关的知识,希望对你有一定的参考价值。
有以下数据: let a = new Set([ ‘categoryId‘: 1, ‘categoryIdLevelOne‘: 750611334, ‘categoryIdLevelThree‘: 750611336, ‘categoryIdLevelTwo‘: 750611335, ‘id‘: 2697, ‘level‘: 3, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 1 , ‘categoryId‘: 2, ‘categoryIdLevelOne‘: 750611472, ‘categoryIdLevelTwo‘: 750611473, ‘id‘: 2701, ‘level‘: 2, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 2 , ‘categoryId‘: 3, ‘categoryIdLevelOne‘: 750611487, ‘categoryIdLevelTwo‘: 750611488, ‘id‘: 2702, ‘level‘: 2, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 1 ]) let b = new Set([ ‘categoryId‘: 2, ‘categoryIdLevelOne‘: 750611334, ‘categoryIdLevelThree‘: 750611336, ‘categoryIdLevelTwo‘: 750611335, ‘id‘: 2697, ‘level‘: 3, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 1 , ‘categoryId‘: 3, ‘categoryIdLevelOne‘: 750611472, ‘categoryIdLevelTwo‘: 750611473, ‘id‘: 2701, ‘level‘: 2, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 2 , ‘categoryId‘: 4, ‘categoryIdLevelOne‘: 750611487, ‘categoryIdLevelTwo‘: 750611488, ‘id‘: 2702, ‘level‘: 2, ‘shopId‘: 12430, ‘skipLayoutFlag‘: false, ‘status‘: 1 ]) 交集 [...a].filter(x => [...b].some(y => y.categoryId === x.categoryId)) //或者 Array.from(a).filter(x => Array.from(b).some(y => y.categoryId === x.categoryId)) 差集 [...a].filter(x => [...b].every(y => y.categoryId !== x.categoryId)) 去重 this.selectTable = this.selectTable.reduce(function(item, next) hash[next.id] ? "" : (hash[next.id] = true && item.push(next)); return item; , []);
以上是关于数组对象 级别 交集的主要内容,如果未能解决你的问题,请参考以下文章
Python计算两个numpy数组的交集(Intersection)实战:两个输入数组的交集并排序获取交集元素及其索引如果输入数组不是一维的,它们将被展平(flatten),然后计算交集