Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
pop() Method / Delete element - Array Function - Javascript (JS) Tutorial

Javascript pop() Method - Array Function

How to delete an element from the array and get the deleted element as the return value?
What is the use of pop() function in javascript?

Explanation

Method: pop() :
This method is used to delete the last element of an array and to return the deleted element. The length of the array gets affected by this function.
Syntax:
array1.pop();

Example:


<script language="javascript">
var stack=["a","b","c","d"]
var ele = stack.pop();
document.write(ele);
</script>

Result:




Ask Questions

Ask Question