json traversal in js

Solutions on MaxInterview for json traversal in js by the best coders in the world

showing results for - "json traversal in js"
Théodore
09 Aug 2019
1Object.entries(jsonObj).forEach(([key, value]) => {
2    // do something with key and val
3});
4
Lise
10 Aug 2016
1function traverse(jsonObj) {
2    if( jsonObj !== null && typeof jsonObj == "object" ) {
3        Object.entries(jsonObj).forEach(([key, value]) => {
4            // key is either an array index or object key
5            traverse(value);
6        });
7    }
8    else {
9        // jsonObj is a number or string
10    }
11}
12