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

237
Visualizações
why inline `push()` doesn't work on new created array?

I am creating an Array with length of 1,000,000 and filling it with 1 like this:

const bigArray = Array.from({ length: 1000000 }, () => 1);

when I push a new item to that Array just inline as bellow, Nodejs logs an error:

// This rise an TypeError: bigArray.push is not a function
const bigArray = Array.from({ length: 1000000 }, () => 1).push(3);

// Although this one works right
const bigArray = Array.from({ length: 1000000 }, () => 1);
bigArray.push(3)

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

According to MDN, Array#push returns the new length of the array, not the array itself:

Return value
The new length property of the object upon which the method was called.

The code you provided works in any node engine otherwise.

about 4 years ago · Juan Pablo Isaza Relatório

0

As an alternative to that approach to keep things in one assignment, you could spread the array into a new array:

const bigArray = [...Array.from({ length: 1000000 }, () => 1), 3];
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