-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
45 lines (35 loc) · 946 Bytes
/
array.js
File metadata and controls
45 lines (35 loc) · 946 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
42
43
44
45
// creating array
const arr = [10,25,30,45, 'Hello', 'World', 4.5,];
// Multi Dimensional Array
const multiArr = [[1,2,3], ['Hello', 'Sprilte',], [31.5, 23.5, 34.6]];
// accessing array using indexes
console.log(arr[5]);
console.log(multiArr[2][1]);
// modifying array using indexes
console.log(arr[4] = 'Bye');
console.log(arr[1][1] = 'World!');
// push method
arr.push(1)
console.log(arr);
multiArr.push([10,37.8,'Spritle'])
console.log(multiArr);
// pop method
console.log(arr.pop());
console.log(multiArr.pop());
console.log(multiArr[2].pop());
// shift
console.log(arr.shift());
console.log(multiArr.shift());
console.log(multiArr[1].shift());
// unshift
arr.unshift(20.4)
console.log(arr);
multiArr.unshift(100);
console.log(multiArr);
slice
console.log(arr.slice(1,3));
console.log(arr);
console.log(multiArr.slice(0,4));
// splice
const array = arr.splice(1,3);
console.log(array);