Answers for "how to iterate through an object and also nested object in javascript"

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;
}
Posted by: Guest on April-07-2020
0

how to iterate through an object and also nested object in javascript

var fireRefTeacher = firebase.database().ref("object");



fireRefTeacher.once("value", function(snapshot){
  snapshot.forEach(function(element){

    var subjects = element.val().TheNestedObject;


    var modules = Object.values(subjects);

    
     document.querySelector('#theid').innerHTML += 
      `

        <li id="letitbe"><span id="spana">${element.val().theValue} ${element.val().theValue}</span><small style="margin-left: 10px;">${modules}</small></li>
`

    ;

    
  })
})
Posted by: Guest on August-21-2021

Code answers related to "how to iterate through an object and also nested object in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language