forked from DouglasHdezT/JavaScript_NodeCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.js
More file actions
41 lines (32 loc) · 958 Bytes
/
Example2.js
File metadata and controls
41 lines (32 loc) · 958 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
/**
* Concat, slice and splice
*/
let array1 = [1, 2, 3, 4];
let array2 = [4, 3, 2, 1];
/**
* Concat join two arrays, and return a new instace of Array with the result. Dont alter both originals arrays
*/
const concatArrays = () => {
let array3 = array1.concat(array2);
console.log(array3);
}
/**
* Slice return a copy of part of an array in a new instace of Array. Dont alter original array.
*/
const sliceArrays = () => {
//The begin position is included, and the end position is excluded
let arraySliced = array1.slice(0, 2);
console.log(arraySliced);
}
/**
* Splice returns a part of an array, deleting it from the original array.
*/
const spliceArrays = () => {
//The begin position is included, and the end position is excluded
let arraySpliced = array1.splice(0, 2);
console.log(`Subarray: ${arraySpliced}`);
console.log(`New array: ${array1}`);
}
concatArrays();
sliceArrays();
spliceArrays();