Skip to content

Commit 708332c

Browse files
committed
updated spread operators
1 parent b7940d5 commit 708332c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Array Method: spread operator (...)
5+
//
6+
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
7+
//
8+
// for function calls:
9+
// myFunction(...iterableObj);
10+
//
11+
// for array literals or strings:
12+
// [...iterableObj, '4', 'five', 6];
13+
//
14+
// for object literals:
15+
// let objClone = { ...obj };
16+
//
17+
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
18+
//
19+
// • "..." spread operator is used combine arrays.
20+
// • "..." spread operator is similar to the concat method.
21+
// • "..." spread operator "spreads" all of the combined elements of the array individually.
22+
// • To create a new array using different arrays using the spread operator, eclare a new array THEN
23+
// inside the new array we are adding the individual elements of the first and second arrays.
24+
// • The spread operator allows you to have greater flexibility than concat method, for example you could
25+
// add another element to certain parts of the array besides
26+
//
27+
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
28+
//
29+
// EXAMPLE 1: Combine two arrays
30+
//
31+
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
32+
//
33+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
35+
36+
37+
// EXAMPLE 1: Combine two arrays
38+
39+
const myArray1 = [1,2,3,4];
40+
const myArray2 = [5,6,7,8];
41+
42+
43+
function combo(array1, array2) {
44+
const combinedSpread = [...array1, ...array2];
45+
console.log(combinedSpread);
46+
}
47+
48+
combo(myArray1, myArray2);

0 commit comments

Comments
 (0)