如何从其他数组中获得一个数组的差异?

时间:2016-04-07 09:11:07

标签: javascript lodash

我有:



mncs: [ [ 0 ], [ 3 ], [ 5 ], [ 90 ] ],
upMncs: [ [ 0 ], [ 3 ], [ 90 ] ],

criteria.mncs
criteria.upMncs




我需要 addMncs:[[5]],来从第一个数组中剪切相同的元素并获得不同的颜色 我用lodash 请帮忙

1 个答案:

答案 0 :(得分:1)

您可以在difference之后使用flatten

var criteria =  {
mncs: [ [ 0 ], [ 3 ], [ 5 ], [ 90 ] ],
upMncs: [ [ 0 ], [ 3 ], [ 90 ] ],
}
console.log(_.difference(_.flatten(criteria.mncs), _.flatten(criteria.upMncs))) 
// [5]