0
点赞
收藏
分享

微信扫一扫

typescript 2个对象数组去重

Gaaidou 2022-04-27 阅读 124
typescript
/**
 * @description:2个对象数组去重复值,根据key
 * @param {*}
 * @return {*}
 */

const uniq = (arr1: any[], arr2: any[], key: string) => {
  let ids = arr2.map((item) => item[key])
  console.log(ids)
  return arr1.filter((el) => {
    return !ids.includes(el[key])
  })
}
console.log(uniq(arr1, arr2, "id"));
举报

相关推荐

0 条评论