dict.get() for javascript to parse fetch data

Is there a way I can do this in javascript?

events_json = events.json()
for detect in events_json.get("detections"):

This didn’t seem to work in javascript:

for (let i = 0; i < data.length; i++) {

Any suggestions to get this working in javascript? I tried following this link but wasn’t able to understand how to use it for this: What is the Javascript equivalent of Python’s get method for dictionaries


You need to quote detections and source_location so they’ll be literals, not variables, just like you do in Python. You can also use . notation in JavaScript for property name literals.

data.detections.forEach(detect => console.log(detect.source_location));