Reputation: 51
labels
is a dictionary of dictionaries :
{"1":{"id":"1","image":"1-0.png","name":"","xMax":"4802","xMin":"4770","yMax":"156","yMin":"141"},"2":{"id":"2","image":"1-0.png","name":"","xMax":"4895","xMin":"4810","yMax":"157","yMin":"141"},"3":{"id":"3","image":"1-0.png","name":"","xMax":"4923","xMin":"4903","yMax":"156","yMin":"145"},"4":{"id":"4","image":"1-0.png","name":"","xMax":"4956","xMin":"4931","yMax":"156","yMin":"145"}}
what I want is :
for (i = 0; i < labels.length; i++){
drawLabels(
labels[i].id,
labels[i].xMin,
labels[i].xMax,
labels[i].yMin,
labels[i].yMax
);
}
I have 4 dictionaries in the main dictionary so I want their content used 1 by 1 but labels.length isn't working not even the way I'm accessing my dictionary elements below.
How can I fix my code to do so?
Upvotes: 1
Views: 137
Reputation: 5657
labels
isn't an array.
You should do it like this :
for (let i in labels){
if(labels.hasOwnProperty(i)) {
drawLabels(
labels[i].id,
labels[i].xMin,
labels[i].xMax,
labels[i].yMin,
labels[i].yMax
);
}
}
Upvotes: 2