Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Adding a single array of an array into an array of a multidimensional array in Excel Scripts/ Javascript

looking to add a single array into a multidimensional array or an array of arrays.

for example:

Data = [["A","B","C","D"]];

NewData =[[1,2,3,4],[5,6,7,8],[9,10,11,12]];

CombinedData = [];

for(i=0; i< NewData.length; i++){
  CombinedData.push(...Data,NewData[i]);
}

However the above results in this: "CombinedData =[["A","B","C","D"],[1,2,3,4],["A","B","C","D"],[5,6,7,8],["A","B","C","D"],[9,10,11,12],["A","B","C","D"]....]"

Where what I am looking for is this: "CombinedData =[["A","B","C","D",1,2,3,4],["A","B","C","D",5,6,7,8],["A","B","C","D",9,10,11,12],]"

This is in ExcelScripts or office scripts which I know is pretty new but just looking for some sort of direction.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to spread both arrays and wrap in in brackets to make a new array.

const Data = ["A","B","C","D"];
const NewData =[[1,2,3,4],[5,6,7,8],[9,10,11,12]];
var CombinedData = [];

for(i=0; i< NewData.length; i++){
  CombinedData.push([...Data,...NewData[i]]);
}

console.log(CombinedData);

Also, you could just use map instead of the for loop:

const Data = ["A","B","C","D"];
const NewData =[[1,2,3,4],[5,6,7,8],[9,10,11,12]];
var CombinedData = NewData.map(x=>[...Data, ...x]);
console.log(CombinedData);

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda