Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active August 31, 2021 14:34
Show Gist options
  • Save tararoutray/0a78900e7e65eea6ea5dc62af9d043a4 to your computer and use it in GitHub Desktop.
Save tararoutray/0a78900e7e65eea6ea5dc62af9d043a4 to your computer and use it in GitHub Desktop.
// Let's declare an array of DC heros
let dcHeros = [
'Superman', 'Batman', 'Wonder Woman'
];
// Now let's declare another array of Marvel heros and merge both the arrays
// The spread operator will extract the values of the previous array (dcHeros)
// to the current array.
let marvelAndDcHeros = [
'Captain America', 'Ironman', 'Hulk', ...dcHeros
];
// Loop through the new array
for (let hero of marvelAndDcHeros) {
console.log(hero);
}
// Above will output:
// Captain America
// Ironman
// Hulk
// Superman
// Batman
// Wonder Woman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment