A more refined Javascript typeof?

This question already has an answer here:

  • Check if object is array? 38 answers

  • 您不能扩展typeof运算符,但为了更好地进行类型检查,您可以(ab)使用Object.prototype.toString

    Object.prototype.toString.call([]) === '[object Array]'
    Object.prototype.toString.call(document) === '[object HTMLDocument]`
    

    You can use Array.isArray() for it.

    The Array.isArray() method returns true if an object is an array, false if it is not.

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

    上一篇: 无论如何要知道特定类型的JavaScript变量

    下一篇: 更精致的Javascript类型?