基于ES6的集合去重

64 阅读1分钟

去重对象:my_list

数组格式:my_list: [
{code: 'code', name: 'name'},
...
]

let object = {}
let tmp = _this.my_list
_this.my_list = tmp.reduce((cur, next) => {
  // eslint-disable-next-line no-unused-expressions
  object[next.code] ? '' : object[next.code] = true && cur.push(next)
  return cur
}, [])