DEV Community

Discussion on: 7 Killer JavaScript One-Liners that you must know

Collapse
 
alokikpathak profile image
Alokik Pathak

Cool...

Get unique items of array

const arrayWithDuplicate = [1,1,2,3,3,4,4,1];
const arrayWithoutDuplicate = [...new Set(arrayWithDuplicate)]; // [1,2,3,4]
Enter fullscreen mode Exit fullscreen mode

Get common items between two array

const arr1 = [3,2,4,5,2];
const arr2 = [3,6,8,23,4];
const arrayWithCommonItem = [...new Set(arr1)].filter(x => arr2.includes(x)); // [3,4]
Enter fullscreen mode Exit fullscreen mode