一般来说,可以使用typeof来判断数据类型,但是数组,对象和null的结果都是object,那么如何区分这三类呢?可以使用如下方法: var arr = []; var obj = {} var empty = null; var a = Object.prototype.toString.call(arr); //[object Array] var b = Object.prototype.toString.call(obj); //[object Object] var c = Obje…
判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异同. 先举几个例子: var a = "iamstring."; ; ,,]; var d = new Date(); );}; ";}; 1.最常见的判断方法:typeof alert(typeof a) ------------> string alert(typeof…