Learn, grow and help others with BBBootstrap
Contribute us with some awesome cool snippets using HTML,CSS,JAVASCRIPT and BOOTSTRAP
The easiest way to remove the duplicates from an array is using a set function in javascript.
const letters = ['a','a','b','c','c','c','d','e']; const unique = [...new Set(letters)]; console.log(unique); // a,b,c,d,e
duplicates from an array in JavaScript ES6 can also be removed using reduce
function
const letters = ['a','a','b','c','c','c','d','e']; const unique = letters.reduce((result,letter) => { return result.includes(letter) ? result : [...result,letter]; },[]); console.log(unique);
duplicates can also be removed using filter method. try using code below
const letters = ['a','a','b','c','c','c','d','e']; const unique = letters.filter((letter,index) => { return letters.indexOf(letter) === index; },[]); console.log(unique);