Answers for "how to take duplicate numbers from list in 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 get duplicate values from array in javascript

let a = [1, 2, 3, 4, 2, 2, 4, 1, 5, 6]
let b = [...new Set(a.sort().filter((o, i) => o !== undefined && a[i + 1] !== undefined && o === a[i + 1]))]

// b is now [1, 2, 4]
Posted by: Guest on June-19-2020
0

function that duplicates data in array js

function doubleValues(array) {
  var newArray = [];
  array.forEach(function (el) { newArray.push(el, el); });    
  return newArray;
}

console.log(doubleValues([1,2,3]));
Posted by: Guest on April-22-2021
0

how to take duplicate numbers from list in js

let array = [1,4,7,3,8,4,3,2,1,23,4312,4312,2,2,5,3];

array.sort((a,b) => a - b);

let prev = 0;
let now = 1;

for (let i = 0; i < array.length; i++) {
  if (array[prev] == array[now]) {
    console.log(array[prev]);
  }
  if (now == array.length) {
    break;
  }
  prev++;
  now++;
}
Posted by: Guest on October-27-2021

Code answers related to "how to take duplicate numbers from list in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language