I have a component which has the following object ('items') in its state:
items:
count: 2
next: null
previous: null
results: Array[2]
0: {…}
id: 1
price: "100.00"
show_in_shop: true
tax_percentage: "5.0000000"
title: 'Object title'
type: "assessment"
1: {…}
id: 2
price: "1000.00"
show_in_shop: true
tax_percentage:"8.0000000"
title: "Title of this object"
type: "class"
I am creating a filter that loops over this.state.items.results and checks if the values of the Item object are in the search query.
However, I am running into the following problem, when I run this code:
for (let item in this.state.items.results) {
console.log(item);
What gets printed to the console is
0
1
And not:
0: {…}
id: 1
price: "100.00"
show_in_shop: true
tax_percentage: "5.0000000"
title: 'Object title'
type: "assessment"
1: {…}
id: 2
price: "1000.00"
show_in_shop: true
tax_percentage:"8.0000000"
title: "Title of this object"
type: "class"
But why? When I check the state in the react-chrome plugin I see that the 'item.results' is populated with data and contains more data than is being printed to the console. Does anyone know why the loop is only looping over the index and not returning the object?