Bit of a rookie question & late in the day, but how do I access an array in an object? I am getting undefined & TypeError: Cannot read property 'length' of undefined. I can get the object data (Id, ElemId, etc) fine.
...
this.state = {
yfinder: [],
...
}
...then api call...
this.setState({
finder: res.Finder,
...
})
JSON:
"Finder": {
"Id": "23216245567u4",
"ElemId": "finder",
"Title": "Your Finder",
"Description": "This is a description",
"ResultsTitle": "What program or service are you looking for?",
"CategoryTitle": "Great! Select a category to continue..",
"Results": [
{
...
}
{
...
}
]
}
let finder = this.state.finder;
console.log(finder.Results);
for (var i = 0; i < finder.Results.length; i++) {
console.log(finder.Results[i]);
}
let finder = this.state.Finder