function unique(arr) { return arr.reduce((prev, cur) => prev.includes(cur) ? prev : [...prev, cur], []); }
function unique2(arr) { var result = []; for (var i=0; i<arr.length; i++) { if (!result.includes(arr[i])) { result.push(arr[i]) } } return result; }
function unique(arr) { var result = []; for (var i=0; i<arr.length; i++) [ if(result.indexOf(arr[i]) === -1) { result.push(arr[i]) } ] return result; }
Array.from(new Set(arr)); [...new Set(arr)];
对象数组去重
let obj = {}; arr = arr.reduce((prev, cur) => { obj[cur.userId] ? "" : obj[cur.userId] = true && prev.push(cur); return prev; }, [])