Program to use JavaScript Array shift() method
let a = [1,2,3,4,5];
let b = a.shift();
console.log(a);
console.log(b);
Output
[ 2, 3, 4, 5 ]
1
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of array
a = [1,2,3,4,5]
andb = a.shift()
- The
array shift()
method removes the first element of an array. - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array shift() method
let c = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'];
let d = c.shift();
console.log(c);
console.log(d);
Output
[ 'Good Afternoon', 'Good Evening', 'Good Night' ]
Good Morning
Steps Description
- Declare two variable
c
andd
- Initialize two variable with value of array
c = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night']
andd = c.shift()
- The
array shift()
method removes the first element of an array. - The value of
d
variable is displayed with the help of console.log inbuilt function