-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
35 lines (26 loc) · 729 Bytes
/
array.js
File metadata and controls
35 lines (26 loc) · 729 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
// implementing basic functions for array
const array = [2,5,1,9,6,7];
array[4];
// inserting element to tail
array.push(4);
// inserting or updating value in index x
array[8] = 3;
console.log(array);
// [ 2, 5, 1, 9, 6, 7, 4, <1 empty item>, 3 ]
// inserting elements on head which changes index of all emement
array.unshift(0);
console.log(array);
// deleting element in x index
// splice modifies original array "array"
array.splice(4, 2);
console.log(array);
// deleting element from the beginning of array
array.shift();
console.log(array);
// deleting element from the middle
// again using splice
array.splice(2,1);
console.log(array);
// deleting element from the last position
array.pop();
console.log(array);