I have made a request to an API that is returning a JSON array like this:
My end goal is to take the attribute "State" and find all the "EventName" (s) where State: "PR" (or another state. I am getting the State input from a user dropdown) and put that into a list.
I know I can use the index (Ex: event_data[0].State returns "PR") to get the individual attributes but how can I avoid using the index to get all the State value (or EventName values) in the entire Array? Or is that even wise?
I have tried the below, but it seemed to just grab all of the EventName values rather than just those for "PR". The expected output should be a list of event names for just "PR" like pr_list = ["Debby 2000", "Dean 2001", "Jeane 2004" ... "Maria 2017"];
pr_list = [];
for (i = 0; i < event_data.length; i++) {
state_data = event_data[i].State;
if (state_data = "PR") {
console.log(event_data[i].EventName)
pr_list.append(event_data[i].EventName);
}
}

ifstatement:if (state_data = "PR")- you're performing assignment, not comparison, thats why it takes alleventNameand not just those with State equal to "PR"