加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

数组 – 如何在angularjs中的多维数组中查找重复值

发布时间:2020-12-17 07:14:22 所属栏目:安全 来源:网络整理
导读:var arrayValues = [[2,3,5],[3,5]]var commonArrayValues = _.intersection(arrayValues); 目前正在工作, _.intersection([[2,5]]) Result: [2,5] 但它应该工作,(即外部数组应删除) _.intersection([2,5]) Expected Result: [3,5] 任何人都能给我一个合适的
var arrayValues = [[2,3,5],[3,5]]
var commonArrayValues = _.intersection(arrayValues);

目前正在工作,

_.intersection([[2,5]])
    Result: [2,5]

但它应该工作,(即外部数组应删除)

_.intersection([2,5])
    Expected Result: [3,5]

任何人都能给我一个合适的解决方案.先感谢您.

解决方法

您可以使用 apply和 intersection来获得您想要的:

var result = _.intersection.apply(null,arrayValues);
var arrayValues = [[2,[2,5,6]]

var result = _.intersection.apply(null,arrayValues);

document.getElementById('results').textContent = JSON.stringify(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore.js"></script>

<pre id="results"></pre>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读