-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-pop.js
More file actions
68 lines (41 loc) · 1.32 KB
/
Copy pathpush-pop.js
File metadata and controls
68 lines (41 loc) · 1.32 KB
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
59
60
61
62
63
64
// add elements to an array
var lastBench = ['kalam', 'balam', 'salam'];
lastBench.push('jalam');
lastBench.push('palam');
lastBench.push('malam');
console.log(lastBench);
var friendsAge = [11, 13, 17, 12];
console.log(friendsAge);
var friendsAge = [11, 13, 17, 12];
friendsAge.push(21);
friendsAge.push(28);
console.log(friendsAge);
// remove elements from an array
friendsAge.pop();
console.log(friendsAge);
// remove elements from an array
friendsAge.pop();
friendsAge.pop();
console.log(friendsAge);
// remove elements from an array
friendsAge.pop();
console.log(friendsAge);
// remove elements from an array
var lastItem = friendsAge.pop();
// friendsAge.pop();
console.log(friendsAge);
console.log(lastItem);
// ***** Remove the first item of an array: ******
var fruits = ["Banana", "Orange", "Apple", "Mango"];
// fruits.shift();
console.log(fruits);
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
console.log(fruits);
//The Array.unshift() method adds new items to the beginning of an array:
const fruitsNatural = ["Cocunut", "Banana", "Orange", "Apple", "Mango"];
// fruits.unshift("Lemon", "Pineapple");
console.log(fruitsNatural);
const fruitsNaturalMore = ["Cocunut", "Banana", "Orange", "Apple", "Mango"];
fruitsNaturalMore.unshift("Lemon", "Pineapple");
console.log(fruitsNaturalMore);