javascript pop() method


  Translation results:

英[pɒp]   美[pɑ:p]   

vi. (Unexpectedly, suddenly) appear; appear suddenly; make a crackling sound; (suddenly) act

vt. (suddenly) reach out; (suddenly) ask a question; (suddenly take out something prepared); knock

n. pop music; soda; (especially used as a title) dad; (quickly) marked) mark

adj.Pop music;popular style;popular;modern

adv.explosion;bang

abbr.post office agreement protocol)

Third person singular: pops Plural: pops Present participle: popping Past tense: popped Past participle: popped

javascript pop() methodsyntax

How to use the pop() method?

The pop() method is used to delete the last element in a JavaScript array and return the last element of the array.

Function: Used to delete and return the last element of the array.

Syntax: arrayObject.pop()

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

Returns: The last element of arrayObject.

javascript pop() methodexample

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    var arr = new Array(3)
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"

    document.write(arr)

    document.write("<br />")

    document.write(arr.pop())

    document.write("<br />")

    document.write(arr)

</script>
</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A