how to find duplicate number in an array code example

Example 1: how to get duplicate values from array in javascript

var array = [1, 2, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 5, 22, 1, 2, 511, 12, 50, 22];

console.log([...new Set(
  array.filter((value, index, self) => self.indexOf(value) !== index))]
);

Example 2: find-array-duplicates

npm i find-array-duplicates

import duplicates from 'find-array-duplicates'

const names = [
 { 'age': 36, 'name': 'Bob' },
 { 'age': 40, 'name': 'Harry' },
 { 'age': 1,  'name': 'Bob' }
]
 
duplicates(names, 'name').single()
// => { 'age': 36, 'name': 'Bob' }