2016-04-07 60 views
-3

我:如何從其他數組中獲取差異之一?

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

 
criteria.mncs 
 
criteria.upMncs

我需要得到addMncs:[[5]],削減從第一陣列相同的元素,不像
我用lodash 幫助獲取請

+0

你有什麼代碼? –

回答

1

您可以在flatten之後使用difference

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

我知道_.flatten,是的,它很聰明)謝謝 – AxOn