Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get duplicate value javascript

const yourArray = [1, 1, 2, 3, 4, 5, 5]

const yourArrayWithoutDuplicates = [...new Set(yourArray)]

let duplicates = [...yourArray]
yourArrayWithoutDuplicates.forEach((item) => {
  const i = duplicates.indexOf(item)
  duplicates = duplicates
    .slice(0, i)
    .concat(duplicates.slice(i + 1, duplicates.length))
})

console.log(duplicates) //[ 1, 5 ]
Source by flaviocopes.com #
 
PREVIOUS NEXT
Tagged: #duplicate #javascript
ADD COMMENT
Topic
Name
7+4 =