@@ -32,3 +32,63 @@ console.log(names);
32
32
names [ names . length ] = "Added" ;
33
33
console . log ( names ) ;
34
34
35
+ var country = [ "Pakistan" , "India" , "Bangladesh" ] ;
36
+ console . log ( country ) ;
37
+
38
+ //Methods Of Array :
39
+ // 1.Push
40
+ // 2.Pop
41
+ // 3.Shift
42
+ // 4.Unshift
43
+ // 5.Splice
44
+ // 6.Slice
45
+
46
+ // Push == To Add Element in the end of an array
47
+ country . push ( "China" , "Afghanistan" ) ;
48
+ console . log ( "After Push : " , country ) ;
49
+
50
+ // Pop == To Remove last element from array
51
+ country . pop ( ) ;
52
+ console . log ( "After Pop : " , country ) ;
53
+
54
+ // UnShift == To Add value in the start of array
55
+ country . unshift ( "Sri Lanka" ) ;
56
+ console . log ( "After Unshift : " , country ) ;
57
+
58
+ // Shift == To remove first element from array
59
+ country . shift ( ) ;
60
+ console . log ( "After Shift : " , country ) ;
61
+
62
+ // Splice == To add or remove from particular index of array
63
+ var fruits = [ "Apple" , "Mango" , "Banana" , "PineApple" , "Strawberry" , "Guava" ] ;
64
+
65
+ // To add at particular index
66
+ fruits . splice ( 1 , 0 , "Peach" , "Leeche" ) ;
67
+ console . log ( fruits ) ;
68
+
69
+
70
+ // To remove from particular index
71
+
72
+ var deleted = fruits . splice ( 2 , 1 ) ;
73
+ console . log ( "Deleted Value : " , deleted ) ;
74
+ console . log ( fruits ) ;
75
+
76
+ // To add or remove both
77
+
78
+ var updated = fruits . splice ( 4 , 1 , "Kiwi" ) ;
79
+ console . log ( "Updated Value : " , updated ) ;
80
+ console . log ( fruits ) ;
81
+
82
+ //Slice == Use to copy element
83
+
84
+ var copy3 = fruits . slice ( 1 , 4 ) ;
85
+ console . log ( "Copied : " , copy3 ) ;
86
+ console . log ( fruits ) ;
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
0 commit comments