Skip to content

Instantly share code, notes, and snippets.

@nathan-lapinski
Created June 4, 2018 12:01
Show Gist options
  • Save nathan-lapinski/0027ef89f5b3f6e718c06ff7e22c6a87 to your computer and use it in GitHub Desktop.
Save nathan-lapinski/0027ef89f5b3f6e718c06ff7e22c6a87 to your computer and use it in GitHub Desktop.
Nested Arrays
const gameData = [
{
title: 'Mega Man 2',
bosses: [
{
name: 'Bubble Man',
weapon: 'Bubble Beam'
},
{
name: 'Metal Man',
weapon: 'Metal Blade'
}]
},
{
title: 'Mega Man 3',
bosses: [
{
name: 'Gemini Man',
weapon: 'Gemini Laser'
},
{
name: 'Top Man',
weapon: 'Top Spin'
}]
}
];
// return an array of all bosses
const bossesArray = gameData.map(game => {
return game.bosses;
});
// uh oh, those are nested arrays!
// [[{},{}],[{},{}]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment