How to use JavaScript Array pop()

Array pop

Array pop() method

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

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

Array pop() method

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

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