JS tips [] array compare different out

concatThe combined array
filterprocessing array
indexOffor the first time the position of
lastIndexOflast occurrence position

If there are identical elements, inclusive return different positions (return false)
if only one element, the same position and last position (return true)

let a = [1,3,4], b = [2,3,4];
let c = a.concat(b).filter((cur, i, arr) => {
    return arr.indexOf(cur) ==== arr.lastIndexOf(cur);
}); // c = [1,2]

Guess you like

Origin www.cnblogs.com/codesyofo/p/11281063.html