Home » JavaScript

Array pop() method with example in JavaScript

JavaScript pop() method: Here, we are going to learn about the pop() method of array in JavaScript.
Submitted by IncludeHelp, on February 27, 2019

JavaScript pop() method

pop() method is used remove an element from the end of an array, it changes the length of the array.

Syntax:

    array_name.pop();

Examples:

    Input:
    var countries = ["INDIA", "USA", "UK", "CANADA", "RUSSIA"];

    Function call:
    countries.pop();
    countries.pop();
    countries.pop(); 
    
    Output:
    "INDIA", "USA"

JavaScript Code to demonstrate example of Array.pop() method

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		var countries = ["INDIA", "USA", "UK", "CANADA", "RUSSIA"];
		document.write("countries: " + countries + "<br>");
		document.write("length is: " + countries.length + "<br>");
		
		//removing elements
		countries.pop();
		countries.pop();
		countries.pop();

		document.write("countries: " + countries + "<br>");
		document.write("length is: " + countries.length + "<br>");		
	</script>
</body>
</html>

Output

countries: INDIA,USA,UK,CANADA,RUSSIA
length is: 5
countries: INDIA,USA
length is: 2





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.