1const arr1 = [1,2,3]
2const arr2 = [4,5,6]
3const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
1const a = ['to', 'code'];
2const b = ['learning', ...a, 'is', 'fun'];
3console.log(b); //> ['learning', 'to', 'code', 'is', 'fun']
1////////////////////////////////////////////////////////////////////
2////// SPREAD SYNTAX ///// Dead Milkmen Lyrics "Punk Rock Girl" ////
3// combining two arrays and multiple items using spread syntax
4// Javascript [...spreadSyntax,] lets you pull out or ("spread")
5// a copy of what's inside the array or object
6// it can also be used to create a new array or object
7
8// EXAMPLE: [...combining, ...twoArrays]
9// hit alt / command j or option / command j
10
11// array 1 type
12const firstArray = ["just", "you", "and", "me"];
13// array 2 type
14const secondArray = ["punk", "rock", "girl"];
15
16// (hit return) to store the arrays
17// combine them into a new array using a syntax
18// [...arrayName, ...arrayName];
19
20const newArray = [...firstArray, ...secondArray];
21// (hit return) The items get spread out
22// then combined together
23// call your third Array then (hit return)
24
25newArray
26// answer
27(7) ["just", "you", "and", "me", "punk", "rock", "girl"]
28
29// This could also be done with an array and an "added string"
30const sillyString = ["We'll dress like Minnie Pearl ", ...newArray];
31// (hit return) then call sillyString
32
33sillyString
34// (hit return) answer should be
35(8) ["We'll dress like Minnie Pearl ", "just", "you", "and", "me", "punk", "rock", "girl"]
36
37// You can spread and combine all
38// sorts of silly data that you
39// normally store in an array
40// add another string for fun
41
42const longString = ["And security guards trailed us to a record shop We asked for Mojo Nixon They said he don't work here We said if you don't got Mojo Nixon then your store could use some fixin"];
43
44const moreStuff = [...sillyString, "We went", 2, "a shopping mall", "and", { someProperty: "laughed at all the shoppers" }, ...longString];
45
46// RESULT
47// call moreStuff
48
49moreStuff
50/* RESULT //////////////////////////
51(14) ["We'll dress like Minnie Pearl ",
52"just", "you", "and", "me", "punk", "rock", "girl",
53"We went", 2, "a shopping mall", "and", {…},
54"And security guards trailed us to a record shop
55We…t Mojo Nixon then your store could use some fixin"]
560: "We'll dress like Minnie Pearl "
571: "just"
582: "you"
593: "and"
604: "me"
615: "punk"
626: "rock"
637: "girl"
648: "We went"
659: 2
6610: "a shopping mall"
6711: "and"
6812: {someProperty: "laughed at all the shoppers"}
6913: "And security guards trailed us to a record shop
70We asked for Mojo Nixon They said he don't work here
71We said if you don't got Mojo Nixon
72then your store could use some fixin"
73length: 14
74__proto__: Array(0)
75*/