javascript loop through nested array code example

Example 1: iterate through nested object javascript

function nestedLoop(obj) {
    const res = {};
    function recurse(obj, current) {
        for (const key in obj) {
            let value = obj[key];
            if(value != undefined) {
                if (value && typeof value === 'object') {
                    recurse(value, key);
                } else {
                  	// Do your stuff here to var value
                    res[key] = value;
                }
            }
        }
    }
    recurse(obj);
    return res;
}

Example 2: nested array loop in javascript

let chunked = [[1,2,3], [4,5,6], [7,8,9]];

for(let i = 0; i < chunked.length; i++) {
  
   for(let j = 0; j < chunked[i].length; j++) {
     
      console.log(chunked[i][j]);
   }
}