Skip to content

Commit 6b38df8

Browse files
committed
unshift and shift method
1 parent c2bc415 commit 6b38df8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

0-Arrays/app.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,36 @@ console.log(listArr); //[3, 2, -19, 4, 11, 93, -90, 'test', null, Object {a: 1},
6767
//Array.prototype.pop()
6868
//removes last element from an array
6969
const listToPop = [3, 2, -19];
70-
console.log(listToPop); // [3,2, -19];
70+
console.log(listToPop); // [3, 2, -19];
7171

7272
let resultPop = listToPop.pop();
7373

7474
console.log(listToPop); // [3, 2]
7575
console.log(resultPop); // -19
7676

7777

78+
//Array.prototype.unshift()
79+
//add element in the beginning of an array
80+
const listUn = [3, 2, -19];
81+
console.log(listUn); // [3, 2, -19]
7882

83+
let resultUn = listUn.unshift(100);
84+
console.log(listUn); // [100,3, 2, -19]
85+
console.log(resultUn); // 4
7986

87+
let resultUnN = listUn.unshift(33, 'test');
88+
console.log(listUn); //[33, 'test', 100, 3, 2, -19]
89+
console.log(resultUnN); // 6
8090

8191

92+
//Array.prototype.shift()
93+
//remove element at the beginning of an array
94+
const listSh = ["1A3", 2, -19];
95+
console.log(listSh); // [3, 2, -19]
8296

97+
let resultSh = listSh.shift();
98+
console.log(listSh); // [ 2, -19]
99+
console.log(resultSh); // 1A3 //removed element
100+
101+
102+
//

0 commit comments

Comments
 (0)