Answers for "js duplicate items in array"

1

javascript create array with repeated values

Array(5).fill(2)
//=> [2, 2, 2, 2, 2]
Posted by: Guest on February-17-2021
8

javascript duplicate an array

let arr =["a","b","c"];
// ES6 way
const duplicate = [...arr];

// older method
const duplicate = Array.from(arr);
Posted by: Guest on July-02-2020
0

Find duplicate or repeat elements in js array

function findUniq(arr) {
  return arr.find(n => arr.indexOf(n) === arr.lastIndexOf(n));
}

console.log(findUniq([ 0, 1, 0 ]))
console.log(findUniq([ 1, 1, 1, 2, 1, 1 ]))
console.log(findUniq([ 3, 10, 3, 3, 3 ]))
console.log(findUniq([ 7, 7, 7, 20, 7, 7, 7 ]))
Posted by: Guest on October-11-2021

Code answers related to "js duplicate items in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language