Last active
March 15, 2022 01:01
-
-
Save EliasSalom/e6661caae71b81f6749f960ed62303db to your computer and use it in GitHub Desktop.
ObjectLoop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function LoopOverObject(obj) | |
| { | |
| for (let prop in obj) { | |
| console.log(prop, obj[prop]); | |
| // Check if Arry of (numbers or strings) | |
| if(typeof obj[prop] === 'object' && Array.isArray(obj[prop]) === true) | |
| { | |
| for(let arr of obj[prop]) | |
| { | |
| console.log(">> "+arr); | |
| } | |
| } | |
| // Check if object | |
| else if(typeof obj[prop] === 'object' && Array.isArray(obj[prop]) === false) | |
| { | |
| console.log(obj[prop]); | |
| LoopOverObject(obj[prop]) | |
| } | |
| // print the rest of strings, numbers, boolean | |
| else console.log(">>> "+obj[prop]); | |
| // else if (typeof prop === String || typeof prop === Number || typeof prop ===Boolean) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment