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"):
    print(detect["source_location"])

This didn’t seem to work in javascript:

for (let i = 0; i < data.length; i++) {
        console.log(JSON.stringify(data[detections][i][source_location]) 

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

Answer

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));