我有一個包含對象數組的數組:傳遞一個數組的數組到lodash路口
let data = [[{a:0}, {b:1}], [{a:1}, {b:1}]]
現在,我想使這兩個數組的lodash intersection,返回[{b:1}]
當我做這:
import {intersection} from 'lodash'
return intersection([{a:0}, {b:1}], [{a:1}, {b:1}])
結果是正確的。
但是當我做
return intersection(data)
我只是得到了相同的結果了。
是否有一種簡單的方法可以將所有數據從數據傳遞到相交函數?我最初的想法是使用.map,但這返回另一個數組...
我不認爲你會從中得到任何回報,因爲我相信它是比較引用而不是值。您應該使用['intersectionBy'](https://lodash.com/docs/4.17.4#intersectionBy)或['intersectionWith'](https://lodash.com/docs/4.17.4#intersectionWith)。 – mhodges