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

225
Visualizações
Push each API element on the list

Im trying to pushing each API response on my list :

enter image description here

but unfortunately i got this error

enter image description here

async loadCards() {
  try {
    const response = await axios.get("https://api.adzuna.com/...");
    var list = [];
    response.data.results.forEach(elem => {
      elem.push(list)
      console.log(list)
    });     
  } 
  catch (error) {
    console.log(error);
      }
},
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you are trying to loop through the response and for each result, you wanna enter to the list, right? if so update the code with following

async loadCards() {
  try {
    const response = await axios.get("https://api.adzuna.com/...");
    var list = [];
    response.data.results.forEach(elem => {
      list.push(elem)
      console.log(list)
    });     
  } 
  catch (error) {
    console.log(error);
      }
},

Because you wanna push elements to the list you initialized a simple example is

 const array1 = ['a', 'b', 'c'];
var newarray = []
array1.forEach(element => {
newarray.push(element)});

Here we are taking elements from array1 and pushing them to the new array. Hope it makes sense now

Answering to your comment as you wanna enter the full response and not each element sepeartely you could use this following

async loadCards() {
      try {
        const response = await axios.get("https://api.adzuna.com/...");
        var list = [];
        response.data.forEach(elem => {
          list.push(elem)
          console.log(list)
        });     
      } 
      catch (error) {
        console.log(error);
          }
    },
about 4 years ago · Juan Pablo Isaza Relatório

0

So you could try

    `async loadCards() {
      try {
        const response = await axios.get("https://api.adzuna.com/...");
var string1 = JSON.stringify(response.data);

var parsed = JSON.parse(string1);  
        data = JSON.parse(response.data);
        var list = [];
        parsed.forEach(elem => {
          list.push(elem)
          console.log(list)
        });     
        
      
      } 
      catch (error) {
        console.log(error);
          }
    },` 
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