I am currently facing an issue where I have an object within another object, and my goal is to convert the inner object into a string separated by commas. However, when I attempt to do so, it results in an infinite loop.
After making an observable http request, I receive the data in the following manner:
this._categoryService.getChecklistCategories()
.subscribe(
res => {
this.categories = res;
let newitem:string[];
for(var i=0; i<res.length; i++){
this.categories.map((category, i) => category.no = i+1);
var obj = res[i].assigned; //an obect.
console.log(obj[0]); //get the first index
}
})
The log of 'obj[0]' above displays
https://i.sstatic.net/TSYIx.png
My objective is to generate a string of 'truck_subtype' and append it to this.categories
I attempted the following approach:
res => {
this.categories = res;
let newitem:string[];
for(var i=0; i<res.length; i++){
this.categories.map((category, i) => category.no = i+1);//this adds no i,2,3...
var obj = res[i].assigned; //array item
let stringArray: Array<any> = [];
for(var i=0; i<obj.length; i++){
stringArray.push(obj[i].truck_subtype);
}
this.categories.map((category, i) => category.assigned= stringArray)
}
}
However, the code above leads to an infinite loop and fails to add the string array to this.categories
I'm unable to figure out where I may have gone wrong. Any insights would be appreciated.