Quiero duplicar una matriz con los mismos elementos que contiene la primera matriz Por ejemplo, tengo esta matriz
let array1 = [{title: "test1"}, {title: "Test2"}, {title: "test3"}];necesito transformarlo en
array1 = [{title: "test1"}, {title: "Test2"}, {title: "test3"}, {title: "test1"}, {title: "Test2"}, {title: "test3"}];Muchas gracias.
tratar de concat, como:
let array1 = [{title: "test1"}, {title: "Test2"}, {title: "test3"}]; array1 = array1.concat(array1);No estoy seguro de lo que está tratando de lograr, pero aquí hay una solución.
let array1 = [{title: "test1"}, {title: "Test2"}, {title: "test3"}]; array1 = [ ...array1, ...array1]También puedes lograrlo con un poco for bucle for :)
let arr = [1, 2, 3] ; let new_array = [] ; for(let i = 0 ; i < 2 ; i++) { new_array = new_array.concat(arr) ; } console.log(new_array) ;