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

238
Visualizações
I am getting error push() is not a function while pushing element in array?

I am getting error push() is not a function while pushing element in >array? giving me error lik arry.push is not a function

 var abc=["get","get","get","get","get","get","get","get","get",];
    
     for(i=0;i<abc.length;i++){

    let a=abc[i].push("mate");
 
   console.log(abc);
    }
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

When you do abc[i].push(), you're actually calling .push() on the string at index i, not the array. Strings do not have the function .push() which is where your error is coming from

Instead try the following:

abc.push("mate");
about 4 years ago · Juan Pablo Isaza Relatório

0

To push elements in an array, simply use the Array.prototype.push method.

var abc = ["get", "get", "get", "get", "get", "get", "get", "get", "get"]

abc.push("mate")

Read more about how push works here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push

The origin point of your error is that, you are accessing each array elements which are strings and trying to use the push() method on those.

about 4 years ago · Juan Pablo Isaza Relatório

0

You should delete the [i] in abc[i].push() because abc[i] is string, but the .push() method works for arrays. Therefore you should use abc.push() instead of abc[i].push().

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