How to empty an array

This question already has an answer here:

  • How do I empty an array in JavaScript? 18 answers

  • There are 2 options:

    1) Modify the length property

    var wall = new Array(),
    wall.push(new Rectangle(30, 50, 10, 10));
    
    wall.length = 0;
    

    2) Use the splice() method

    wall.splice(0);
    

    Check this interesting article about the length property.

    链接地址: http://www.djcxy.com/p/23954.html

    上一篇: 更改时删除数组中的所有内容并在其中添加新值

    下一篇: 如何清空数组