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);
// });
});
}
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);
});
});
}
EDIT: While someone asked for a response without foreach loop:

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:
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);
}
});
}