流浪のwolf

卷帝

导航

js中判断数据类型的方法有哪些

判断数据类型可以使用 typeof 但是typeof 判断数组和函数时返回的都是Object 不能具体判断,这时使用 instanceof 可以判断对象是否是另一个函数创造的 ;

用法:

typeof([])   // Object

typeof(12)  // Number

[] instanceof Array   // true 【】是否是数组类型 返回  true 是的

也可以使用数组的静态方法 isArray :

Array.isArray([])   // 返回  true 

posted on 2023-01-25 19:55  流浪のwolf  阅读(13)  评论(0编辑  收藏  举报