写一个函数实现js数组任意类型去重:输入:["a","a",0, 0, {}, {}, {a:1},{a:1},[],[],[1],[1],null, null, undefined,undefined, /\.js$/, /\.js$/]输出:["a", 0 , {}, {a:1}, [], [1], null, undefined, /\.js$/]
2 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
const unique = (array) => { let obj = {} return array.filter((item, index) => { // 防止key重复 let newItem = item + JSON.stringify(item) return obj.hasOwnProperty(newItem) ? false : obj[newItem] = true }) }
添加回答
举报
0/150
提交
取消