Is JavaScript's array.clear() not a function?

This question already has an answer here:

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

  • Nope, it's not. But drawnDivs.length = 0 should work.


    drawnDivs = [];


    It was answered in Stack Overflow question How do I empty an array in JavaScript?.

    Two examples from the answer:

    var A = ['some', 'values', 'here'];
    
    //Method 1
    
    //(This was my original answer to the question)
    
    A = [];
    
    
    
    
    // Method 2 (as suggested by Matthew Crumley)
    
    A.length = 0
    

    And here is a nice write up on these two methods by Dr. Axel Rauschmayer.

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

    上一篇: 如何从数组中删除元素?

    下一篇: JavaScript的array.clear()不是函数吗?