An array of a relatively simple method to weight

// 一种数组去重

union(arr = []) {

return arr.reduce((res, item) => (res.indexOf(item) !== -1 ? res : res.concat(item)), []);

}

The first method is to reduce a parameter callback, the second parameter is the starting value res.

Callback function the first parameter is a result of the execution, the second argument is that each element of the array

Guess you like

Origin blog.csdn.net/qq_41831345/article/details/90262496