Home  >  Article  >  Web Front-end  >  How to use pop() method

How to use pop() method

青灯夜游
青灯夜游Original
2019-02-20 14:29:573904browse

javascript pop() method can be used to delete the last element in a JavaScript array and return the number of deleted elements.

How to use pop() method

javascript pop() method

Function:pop() method Used to remove and return the last element of an array.

Basic syntax:

arrayObject.pop()

Note: pop() method will change the length of the array.

Description: The pop() method will delete the last element of arrayObject, reduce the array length by 1, and return the value of the element it deletes. If the array is already empty, pop() does not modify the array and returns undefined.

Usage example of javascript pop() method

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body style="font-size:20px ;">
<script type="text/javascript">
    var arr = new Array(3)
    arr[0] = "PHP"
    arr[1] = "Javascript"
    arr[2] = "MySQL"
    arr[3] = "Python"
    document.write("原数组:"+arr)
    document.write("<br/><br/>")
    document.write("删除的元素:"+arr.pop())
    document.write("<br/><br/>")
    document.write("新数组:"+arr)
</script>
</body>
</html>

Rendering:

How to use pop() method

The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of How to use pop() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn