A more refined Javascript typeof?
This question already has an answer here:
您不能扩展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.
下一篇: 更精致的Javascript类型?