Created
May 11, 2021 18:55
-
-
Save pjcodesjs/55bf23930b84c870e993ba2620ae4377 to your computer and use it in GitHub Desktop.
This file contains 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
//------------------------------------------------ | |
// COPY ELEMENTS FROM ONE ARRAY INTO ANOTHER ARRAY | |
//------------------------------------------------ | |
const fruits = ['apple', 'mangoe', 'papaya']; | |
const updated_fruits = ['banana', ...fruits]; | |
console.log(updated_fruits); // [ 'banana', 'apple', 'mangoe', 'papaya' ] | |
//------------------- | |
// MERGING TWO ARRAYS | |
//------------------- | |
const my_cats = ['Jimmy', 'Marty', 'Max']; | |
const your_cats = ['George', 'Botsoe', 'Benny']; | |
const our_cats = [...my_cats, ...your_cats]; | |
console.log(our_cats); // [ 'Jimmy', 'Marty', 'Max', 'George', 'Botsoe', 'Benny' ] | |
//---------------- | |
// MERGING OBJECTS | |
//---------------- | |
const profile = { | |
name: 'Dean Winchester', | |
age: 34, | |
car: 'Chevy Imala (Baby)' | |
} | |
const list_of_enemies = { | |
enemy_demons: ['Abadon', 'Yellow Eyes', 'Crowley'], | |
enemy_angels: ['Zacharia', 'Michael', 'Lucifer'] | |
} | |
const character = { | |
...profile, | |
...list_of_enemies | |
} | |
console.log(character); | |
/* | |
{ | |
name: 'Dean Winchester', | |
age: 34, | |
car: 'Chevy Imala (Baby)', | |
enemy_demons: [ 'Abadon', 'Yellow Eyes', 'Crowley' ], | |
enemy_angels: [ 'Zacharia', 'Michael', 'Lucifer' ] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spread Operator Basics.