json traversal in js code example
Example 1: json traversal in js
Object.entries(jsonObj).forEach(([key, value]) => {
// do something with key and val
});
Example 2: json traversal in js
function traverse(jsonObj) {
if( jsonObj !== null && typeof jsonObj == "object" ) {
Object.entries(jsonObj).forEach(([key, value]) => {
// key is either an array index or object key
traverse(value);
});
}
else {
// jsonObj is a number or string
}
}