1. [_.differenceWith(array, [values], [comparator])](https://www.lodashjs.com/docs/lodash.differenceWith#_differencewitharray-values-comparator)

可用于多纬数组比较,结果值是从第一数组中选择。(所以要比较两次)

  1. /**
  2. * 对比一纬或多维数组是否相同
  3. * @param {Array} arr1 数组1
  4. * @param {Array} arr2 数组2
  5. * @return {Boolean} true为不同,false为相同
  6. */
  7. export function _differenceWith(arr1, arr2) {
  8. let result1 = _.differenceWith(arr1, arr2, _.isEqual)
  9. let result2 = _.differenceWith(arr2, arr1, _.isEqual)
  10. // console.log(result1, result2) // [[1]], [[2], 5]
  11. return !!(result1.length || result2.length)
  12. }
  13. _differenceWith([[1], [[4, 5]]], [[2], 5, [[4, 5]]])

2. _.unionBy([arrays], [iteratee=_.identity])

  1. _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  2. // => [{ 'x': 1 }, { 'x': 2 }]