How to add a new value to the end of an numerical array?

This question already has an answer here:

  • How to append something to an array? 25 answers

  • You can use the push method.


    For instance (using Firebug to test quickly) :

    First, declare an array that contains a couple of items :

    >>> var a = [10, 20, 30, 'glop'];
    

    The array contains :

    >>> a
    [10, 20, 30, "glop"]
    


    And now, push a new value to its end :

    >>> a.push('test');
    5
    

    The array now contains :

    >>> a
    [10, 20, 30, "glop", "test"]
    

    You can use

    arrayName.push('yourValue');
    

    OR

    arrayName[arrayName.length] = 'yourvalue';

    Thanks


    您可以使用阵列推送方法

    arrayname.push('value');
    
    链接地址: http://www.djcxy.com/p/17928.html

    上一篇: 将javascript变量存储到数组中

    下一篇: 如何将新值添加到数值数组的末尾?