DEV Community

Tomohiro Yanagi
Tomohiro Yanagi

Posted on • Edited on

get diff from arrays in JavaScript

// getDiff
const hoge = [1,2,3,4,5]
const fuga = [3,4,5,6,7]
[
    ...hoge.filter(v=>!fuga.includes(v)),
    ...fuga.filter(v=>!hoge.includes(v))
]
// [1,2,6,7]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)