To loop through JSON with Node.js, we use the forEach
method.
For instance, we write
const objectKeysArray = Object.keys(yourJsonObj);
objectKeysArray.forEach((objKey) => {
const objValue = yourJsonObj[objKey];
});
to call Object.keys
to get the object’s keys in an array.
Then we call forEach
with a callback to get the property value with yourJsonObj[objKey]
.