How to remove duplicate values from an array - es6

 Set object can be used to remove duplicate values from an array.

const arr = [1,4,7,8,1,9,4];
const result = [...new Set(arr)];

Or

const result = are.reduce((x, y) => x.includes(y) ? x : [...x, y], []);

Or

const result = arr.filter((item, index) => { return arr.indexOf(item) === index; });

Comments

Popular posts from this blog

world tourism guide Template

Es6 how to check if value is not null or undefined?