let enteredDate = document.getElementById('dateBox');
let stringifyData = JSON.stringify(data.cases_time_series)
let parsedData = JSON.parse(stringifyData);
for(let i = 0; i <= parsedData.length; i++){
if(parsedData[i].date == enteredDate){
console.log(parsedData[i])
}
}
console.log(parsedData[0])
In the following code for(let i = 0; i <= parsedData.length; i++){ if(parsedData[i].date == enteredDate){ console.log(parsedData[i]) } }
is returning an error, but console.log(parsedData[0]) is giving me my output. Can anyone tell why is the for loop not working?
Hmm… I think it’s having a problem accessing .date of your parsedData.
I can only make some assumptions since I can’t see the rest of your code. Can you show us what the ‘dateBox’ looks like and the stringified data too? Or better yet, do you have it on a Github?
However, I noticed that the data all has a space after the date string, "30 January " instead of "30 January", so you’ll have to handle that somehow unless you expect users to input dates with a space at the end.