Answers for "count duplicate elements in array js"

2

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))]
);
Posted by: Guest on June-19-2020
0

how to count duplicates in an array javascript

arr.reduce((b,c)=>((b[b.findIndex(d=>d.el===c)]||b[b.push({el:c,count:0})-1]).count++,b),[]);
Posted by: Guest on December-16-2020
0

count duplicate elements in array js

const findDuplicates = (nums) => {
  nums.sort(); // alters original array
  let ans = []

  for(let i = 0; i< nums.length; i++){
    if(nums[i] === nums[i+1]){
       if(ans[ans.length -1] !== nums[i]){
          ans.push(nums[i])
       }
    } 
  }
  return ans;
}
Posted by: Guest on September-06-2021

Code answers related to "count duplicate elements in array js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language