var arrayValues = [[2,3,5],[3,5]]
var commonArrayValues = _.intersection(arrayValues);
目前它的工作方式是,
_.intersection([[2,3,5],[3,5]])
Result: [2,3,5]
但它应该像这样工作(即应该删除外部数组)
_.intersection([2,3,5],[3,5])
Expected Result: [3,5]
任何人都可以给我一个适当的解决方案。预先感谢您。
最佳答案
您可以使用apply与 intersection得到你想要的:
var result = _.intersection.apply(null, arrayValues);
var arrayValues = [[2,3,5],[3,5], [2,3,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>
关于arrays - 如何在angularjs中查找多维数组中的重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34448845/