How to use JavaScript Array pop()

Program to use JavaScript Array pop() method


let a = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'];
let b = a.pop();
console.log(b);

Output


Good Night

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'] and b = a.pop()
  3. Array pop() method removes the last element of the array. and returns the removed element
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array pop() method


let c = [1,2,3,4,5];
let d = c.pop();
console.log(d);

Output


5

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable with value of array c = [1,2,3,4,5] and d = c.pop()
  3. Array pop() method removes the last element of the array. and returns the removed element
  4. The value of d variable is displayed with the help of console.log inbuilt function