-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathspread-syntax.js
More file actions
46 lines (24 loc) · 745 Bytes
/
Copy pathspread-syntax.js
File metadata and controls
46 lines (24 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Objects
const pikachu = { name: 'Pikachu 🐹' };
const stats = { hp: 40, attack: 60, defense: 45 }
'Bad Object Code 💩'
pikachu['hp'] = stats.hp
pikachu['attack'] = stats.attack
pikachu['defense'] = stats.defense
// OR
const lvl0 = Object.assign(pikachu, stats)
const lvl1 = Object.assign(pikachu, { hp: 45 })
'Good Object Code ✅'
const lvl0 = { ...pikachu, ...stats }
const lvl1 = { ...pikachu, hp: 45 }
// Arrays
let pokemon = ['Arbok', 'Raichu', 'Sandshrew'];
'Bad Array Code 💩'
pokemon.push('Bulbasaur')
pokemon.push('Metapod')
pokemon.push('Weedle')
'Good Array Code ✅'
// Push
pokemon = [...pokemon, 'Bulbasaur', 'Metapod', 'Weedle']
// Shift
pokemon = ['Bulbasaur', ...pokemon, 'Metapod', 'Weedle', ]