Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!