Answers for "launch duplicate elements within the array javascript"

0

duplicate an array in javascript n times

const makeRepeated = (arr, repeats) =>
  Array.from({ length: repeats }, () => arr).flat();
  
console.log(makeRepeated([1, 2, 3], 2));
Posted by: Guest on March-26-2021
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

Code answers related to "launch duplicate elements within the array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language