Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda