1//destructuring array
2const alphabet = ['a', 'b', 'c', 'b', 'e'];
3const [a, b] = alphabet;
4console.log(a, b);
5//Expected output: a b
1const book = {
2 title: 'Ego is the Enemy',
3 author: 'Ryan Holiday',
4 publisher: {
5 name: 'Penguin',
6 type: 'private'
7 }
8};
9
10const {title: bookName = 'Ego', author, name: {publisher: { name }} = book, type: {publisher: { type }} = book } = book;
1({ a, b } = { a: 10, b: 20 });
2console.log(a); // 10
3console.log(b); // 20
4
5
6// Stage 4(finished) proposal
7({a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40});
8console.log(a); // 10
9console.log(b); // 20
10console.log(rest); // {c: 30, d: 40}
11
1let renseignement = ['voleur' , '10' , 'spécialité'] ;
2
3
4let [classe , force, magie] = renseignement ;
5
6console.log(classe) ;
7console.log(force) ;
8console.log(magie) ;
1const foo = ['one', 'two', 'three'];
2
3const [red, yellow, green] = foo;
4console.log(red); // "one"
5console.log(yellow); // "two"
6console.log(green); // "three"
7