Photo by Scott Webb on Unsplash
The Shortest Way To Filter And Find The Duplicates Of An Array In JavaScript
When you are working with JavaScript Arrays, It is obvious to know how to remove the duplicates or find the duplicates in Arrays.
Also, it is very mandatory question to in the interview to test your JavaScript Knowledge.
Let's see how to remove the duplicates in Array to start with.
``` let arr = [ 1, 3, 5, 6, 7, 8, 4, 3 ,4, 5, 7]
let result = [...new Set(arr)]
console.log(result)
In the above example, I have declared an array of duplicates and with a single line of code we can remove the duplicates.
Try the same in your console to check the results and play with it.
Now that we have removed the duplicates in the given array, Next step is how to find the duplicates in the given array.
let's see the below example in a single line logic.
```let findDups = arr.filter((i, j, arr) => arr.indexOf(i)!==j)
console.log(findDups)
i - refers to the number of iteration. j - refers to the number of repetition.
Check in the console. Happy Coding :)