Skip to content

Instantly share code, notes, and snippets.

@ilikeprograms
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save ilikeprograms/d0c85ccd4c02b9b8bc68 to your computer and use it in GitHub Desktop.

Select an option

Save ilikeprograms/d0c85ccd4c02b9b8bc68 to your computer and use it in GitHub Desktop.
Object to Array blog post examples
var animals = {
"dogs": ["Husky", "German Sheppard"],
"lizards": ["Comodo Dragon", "Gozzzilla"]
};
var animalBreeds = Object.keys(animals).map(function (animalBreeds) {
return animals[animalBreeds];
});
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);
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