As mentioned in one of my previous tips, array.filter() allow us to filter an array based on the condition that we'll pass here as the argument and this is super handy for a lot of cases. That's what we'll use today.
var arr = [1, 1, 5, 9, 1, 15, 9, 9, 14, 20, 15] console.log(arr) var arrWithoutDuplicates = arr.filter((item, index) => index === arr.indexOf(item)) console.log(arrWithoutDuplicates)
Look at the example to see how we can use the .filter() function on an array to remove all the duplicated elements inside it.
What do you think of these ES6 array functions ? Do you use them in projects or do you prefer doing it the 'old way'? 🤔