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

400
Vistas
Excel Office Script - error trying to push a 2D Array

I'm having an issue of understanding and I'll try to be basic with my problem because it involves lots of data. Here is a simple mockup.

From myArray below, I'm trying to create a new 2D array (arrayFinal) in the form of [[element],[element],[element]], to be able to use a setValues() with Excel Office Script. In this example, each element should have more than 2 elements.

But I'm truly not going anywhere with my way.

I only get a return like, with too many [[[]]] (one too many), and only the last element repeating itself.

[[[1,5,7]],[[1,5,7]],[[1,5,7]],[[1,5,7]],[[1,5,7]],[[1,5,7]]]

Could you have a look and tell me what's the problem ?

let myArray: number[][] = [[1, 2, 3], [2, 4], [5, 6, 7],[1],[2,3],[1,5,7]];

let testArray: (string | boolean | number)[][] = []; 
let arrayFinal: (string | boolean | number)[][] = []; 


myArray.map(x => {
    testArray.length = 0;
    if (x.length > 2) {

       
            testArray.push(x);

       
    }
    arrayFinal.push(testArray);
})
console.log(JSON.stringify(arrayFinal))

Thank you !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I understand it correctly, you are trying to filter the original 2D array to only contain sub-arrays with more than 2 elements, right?

Wondering if you would want to try something like this:

let myArray: number[][] = [[1, 2, 3], [2, 4], [5, 6, 7],[1],[2,3],[1,5,7]];
let arrayFinal = myArray.filter(arr => arr.length > 2);
console.log(JSON.stringify(arrayFinal))

The output should be:

[[1,2,3],[5,6,7],[1,5,7]]
about 4 years ago · Juan Pablo Isaza 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