Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda