;

Javascript Array - pop() Method


Tutorialsrack 15/10/2022 Jquery Javascript

In this article, you will learn about the javascript Array built-in method Array.prototype.pop(). How does this method work in javascript? 

Array.prototype.pop()

The Array.prototype.pop() method is used to remove the last element from an array and returns that element. This method changes the length of the array. 

If the array is empty it returns undefined

Syntax
array.pop();

The pop() method changes the original array.

Here are some examples of Array.prototype.pop() method:

Examples
//Examples of Array.pop() method

const arr = [40, 90, 160, 250, 360];

console.log(arr.pop());
// expected output: "360"

console.log(arr);
// Original Array After popping the element,
// expected output: [40, 90, 160, 250]


const language = ['Java', 'C#', 'Python', 'SQL Server'];


console.log(language.pop());
// expected output: "SQL Server"

console.log(language);
// Original Array After popping the element,
// expected output: ["Java", "C#", "Python"]

I hope this article will help you to understand the javascript Array built-in method Array.prototype.pop()

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags