Quick actions

cmd+k|ctrl+k

Navigation

Languages

makeArrayWithoutDuplicates

Snippet info

Language

JavaScript

Visibility

public

Author

onifademola

Created

2021-06-20T23:13:19.508842Z

Updated

2021-06-21T00:32:35.635525Z

let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']
let myArrayWithNoDuplicates = myArray.reduce(function (accumulator, currentValue) {
  if (accumulator.indexOf(currentValue) === -1) {
    accumulator.push(currentValue)
  }
  return accumulator
}, [])

console.log(myArrayWithNoDuplicates)
INFO