Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get duplicate values from array in javascript

const arr = ["q", "w", "w", "e", "i", "u", "r"]
arr.reduce((acc, cur) => { 
  if(acc[cur]) {
    acc.duplicates.push(cur)
  } else {
    acc[cur] = true //anything could go here
  }
}, { duplicates: [] })
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #duplicate #values #array #javascript
ADD COMMENT
Topic
Name
3+3 =