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

210
Visualizações
why for loop is giving me errors in JSON parsed objects?

I am trying to loop a JSON response from my Web API but it has some unexpected behaviors. The below function is working fine :

  insertListUser(data:any){
    console.log(data);
    this.service.uploadRecords(data).subscribe((res)=>{
      let resArray=JSON.parse(JSON.stringify(res)).body;
      console.log(resArray);
      // resArray.forEach((element:any) => {
      //   console.log(element);
      // });
    });
  }

console log for var resArray But when I try to loop through the Response Array by uncommenting the foreach loop and checking the res var:

  insertListUser(data:any){
    console.log(data);
    this.service.uploadRecords(data).subscribe((res)=>{
      console.log(res);
      let resArray=JSON.parse(JSON.stringify(res)).body;
      console.log(resArray);
      resArray.forEach((element:any) => {
        console.log(element);
      });
    });
  }

Its console log is this: console log of res var

EDIT: While someone asked for a response without foreach loop: res var log

I wanted to add more things I have tried, so this works but result cannot be understood:

  insertListUser(data:any){
    console.log(data);
    let l=data.length;
    this.service.uploadRecords(data).subscribe((res)=>{
      console.log(res);
      let resArray=(JSON.parse(JSON.stringify(res)).body);
      console.log(resArray+" = "+l);
      for(let i in resArray){
        console.log(i);
      }
    });
  }

result: starting... ...ending but when tried this (see the change in for loop):

  insertListUser(data:any){
    console.log(data);
    let l=data.length;
    this.service.uploadRecords(data).subscribe((res)=>{
      console.log(res);
      let resArray=(JSON.parse(JSON.stringify(res)).body);
      console.log(resArray+" = "+l);
      for(let i of resArray){
        console.log(i);
      }
    });
  }

and the results are: The same thing again :(

about 4 years ago · Juan Pablo Isaza
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