I'm facing an issue where I have data that I'm using to create two arrays, but they both end up empty without any errors in the console.
Below is the data:
mydata = {
"id": "661",
"name": "some name",
"description": "some desc",
"subcat": {
"662": {
"id": "662",
"name": "sub 1",
"translations": null
},
"663": {
"id": "663",
"name": "sub 2",
"translations": null
}
},
"image": null
};
Here is the code snippet:
chList=[];
thList=[];
thCount=[];
for (var i = 0; i < mydata.length; i++) {
var obj = mydata[i];
var cl = obj.name;
if (obj.subcat != null) {
chList.push(cl);
}
if(obj.subcat) {
if (i < 10) {
var nme = obj.subcat.map( function(item){
return item.name;
console.log(nme);
});
thList = thList.concat(nme);
thCount.push(nme.length);
}
}
}
console.log(thList);
console.log(thCount);
The issue here is that both thList and thCount end up empty as shown: []
What can be done to fix this problem?