判断js对象是数组还是对象,还是function

Object.prototype.toString.apply([1,2])        //"[object Array]"
Object.prototype.toString.apply('str')        //"[object String]"
Object.prototype.toString.apply(1)            //"[object Number]"
Object.prototype.toString.apply(null)         //"[object Null]"
Object.prototype.toString.apply()             //"[object Undefined]"
Object.prototype.toString.apply(function(){}) //"[object Function]"
Object.prototype.toString.apply(true)         //"[object Boolean]"
Object.prototype.toString.apply(new Object()) //"[object Object]"
Object.prototype.toString.apply(new Date())  //[object Date]"

你可能感兴趣的:(判断js对象是数组还是对象,还是function)