pop()

作者: jeanzy | 来源:发表于2019-12-29 20:26 被阅读0次

    定义和用法

    pop() 方法用于删除并返回数组最后一个元素

    语法

    arrayObject.pop()

    返回值

    arrayObject 的最后一个元素。

    说明

    pop() 方法将删除 arrayObject 的最后一个元素,把数组长度减 1,并且返回删除的元素

    如果数组已经为空,则 pop() 不改变数组,并返回 undefined 值。


    实例

    在本例中,我们将创建一个数组,然后删除数组的最后一个元素。请注意,这也会改变数组的程度:

    var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr)document.write("
    ")document.write(arr.pop())document.write("
    ")document.write(arr)<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>

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

    输出:

    George,John,Thomas

    Thomas

    George,John

    相关文章

      网友评论

          本文标题:pop()

          本文链接:https://www.haomeiwen.com/subject/djluoctx.html