One of the coding interview questions is how to remove duplicates from an array. Of course as for any problem, it has more than one approach in javascript. One of these approaches is to benefit from:

  • Set Object
  • Spread Operator

Here is one of the possible approaches  👇 

function removeDuplicates(arr) {
  return [...new Set(arr)]
}

removeDuplicates([1, 3, 5, 3, 1]); // [1, 3, 5]