首页 > 其他分享 >检测数据类型方法

检测数据类型方法

时间:2023-02-10 17:02:07浏览次数:45  
标签:console log 检测 数据类型 方法 null type

1、typeOf:只能检测基本数据类型 

console.log(typeof 10)//number

2、instanceOf:检测当前实例是否属于某个类的方法 

console.log(arr instanceof Array)//true

3、检测当前实例的构造函数
4、Object.prototype.toString.call( ); 最准确的方式;

console.log(Object.prototype.toString.call(10))//[object Number]

5.jQuery的工具函数判断:$.type()

console.log($.type(null))//null(用此方法检测的数据类型和被检测的数据类型完全一致)

 

标签:console,log,检测,数据类型,方法,null,type
From: https://www.cnblogs.com/zhaofen/p/17109587.html

相关文章