-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deletion_Ways_In_Array.js
58 lines (44 loc) · 1.13 KB
/
Deletion_Ways_In_Array.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Deletion ways in array
var arr = [10,20,1,2,90,33, 88];
undefined
arr.pop(); // delete a element from the last
88
arr;
(6) [10, 20, 1, 2, 90, 33] // result
arr.shift(); // delete a element from the starting
10
arr.splice(1, 1); // From Index 1 delete only one element
[1]
arr;
(4) [20, 2, 90, 33] // result
arr.length=0; // this will remove all the elemets from the array as length is 0 now.
0
arr;
[]
var arr = [10,20,1,2,90,33, 88];
undefined
arr.length = 4; // this will remove all the elemets from the array except staring given length.
4
arr;
(4) [10, 20, 1, 2] // result
var arr = [10,20,1,2,90,33, 88];
undefined
arr = arr.filter(e=>e<30); // this will remove all the elements which are greater than 30. // DECLARATIVE PROGRAMING
(4) [10, 20, 1, 2]
arr;
(4) [10, 20, 1, 2]
var arr = [10,20,1,2,90,33, 88];
undefined
arr = arr.reduce((temp, e)=>{ // this will remove all the elements which are greater than 30. // IMPARATIVE PROGRAMING
if(e<30){
temp.push(e);
}
return temp;
}, []);
(4) [10, 20, 1, 2]
arr;
(4) [10, 20, 1, 2]
arr[0] = 10000; // Updation in array
10000
arr;
(4) [10000, 20, 1, 2]