Last active
August 29, 2015 14:02
-
-
Save ilikeprograms/d0c85ccd4c02b9b8bc68 to your computer and use it in GitHub Desktop.
Object to Array blog post examples
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
| var animals = { | |
| "dogs": ["Husky", "German Sheppard"], | |
| "lizards": ["Comodo Dragon", "Gozzzilla"] | |
| }; |
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
| var animalBreeds = Object.keys(animals).map(function (animalBreeds) { | |
| return animals[animalBreeds]; | |
| }); |
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
| var animals = { | |
| "dogs": ["Husky", "German Sheppard"], | |
| "lizards": ["Comodo Dragon", "Gozzzilla"] | |
| }; | |
| var animalBreeds = []; | |
| for (var i = 0, len = animals.length; i < len; i++) { | |
| for (var z = 0, zLen = animals[i].length; z < zLen; z++) { | |
| console.log(animals[i][z]); | |
| animalBreeds.push(animals[i][z]); | |
| } | |
| } | |
| console.log(animalBreeds); |
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
| var animals = { | |
| "dogs": ["Husky", "German Sheppard"], | |
| "lizards": ["Comodo Dragon", "Gozzzilla"] | |
| }; | |
| var animalBreeds = []; | |
| Object.keys(animals).forEach(function (animalType) { | |
| animalBreeds = animalBreeds.concat(animals[animalType]); | |
| }); | |
| console.log(animalBreeds); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment