js怎么判断对象类型,获取对象值

2025-04-28 23:35:58
推荐回答(1个)
回答1:

对象为object
了解js的都知道, 有个typeof 用来判断各种数据类型,有两种写法:typeof xxx ,typeof(xxx)

如下实例:

typeof 2 输出 number
typeof null 输出 object

typeof {} 输出 object

typeof [] 输出 object

typeof (function(){}) 输出 function

typeof undefined 输出 undefined

typeof '222' 输出 string

typeof true 输出 boolean

这里面包含了js里面的五种数据类型 number string boolean undefined object和函数类型 function