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