Last active
August 31, 2021 14:34
-
-
Save tararoutray/0a78900e7e65eea6ea5dc62af9d043a4 to your computer and use it in GitHub Desktop.
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
// 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