How to remove duplicate values from an array

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

css :Custom Horizontal Rules

Hindi Toolkit