Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get duplicate value javascript

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

let duplicates = []

const tempArray = [...yourArray].sort()

for (let i = 0; i < tempArray.length; i++) {
  if (tempArray[i + 1] === tempArray[i]) {
    duplicates.push(tempArray[i])
  }
}

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