Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get duplicate values from array in javascript

var input = [1, 2, 3, 1, 3, 1];

var duplicates = input.reduce(function(acc, el, i, arr) {
  if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc;
}, []);

document.write(duplicates); // = 1,3 (actual array == [1, 3])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #duplicate #values #array #javascript
ADD COMMENT
Topic
Name
7+2 =