小程序类型判断
程序 类型 判断
2023-09-11 14:14:25 时间
方法1:Object.prototype.toString.call(x)
console.log(Object.prototype.toString.call(10) == '[object Number]')
console.log(Object.prototype.toString.call(str) == '[object String]')
console.log(Object.prototype.toString.call([1,2,3,4]) == '[object Array]')
console.log(Object.prototype.toString.call({name: 'a'}) == '[object Object]')
console.log(Object.prototype.toString.call(new Date()) == '[object Date]')
console.log(Object.prototype.toString.call(undefined) == '[object Undefined]')
console.log(Object.prototype.toString.call(null) == '[object Null]')
方法2:typeof(x)
console.log(typeof(1) == 'number')
console.log(typeof('1') == 'string')
console.log(typeof([1,2,3]) == 'object')
console.log(typeof({name:'1'}) == 'object')
console.log(typeof(new Date()) == 'object')
console.log(typeof(undefined) == 'undefined')
console.log(typeof(null) == 'object')
相关文章
- 创建了对嵌入的互操作程序集间接引用,无法嵌入互操作类型
- SQL 横转竖 、竖专横 (转载) 使用Dapper.Contrib 开发.net core程序,兼容多种数据库 C# 读取PDF多级书签 Json.net日期格式化设置 ASPNET 下载共享文件 ASPNET 文件批量下载 递归,循环,尾递归 利用IDisposable接口构建包含非托管资源对象 《.NET 进阶指南》读书笔记2------定义不可改变类型
- c#程序中使用"like“查询access数据库查询为空的问题
- ubuntu下使用C语言开发一个cgi程序
- 【小程序】安装和配置小程序环境(图文一步步引导)
- 【转】未能加载文件或程序集"System.Web.Extensions, Version=1.0.61025.0, Culture=neutral...
- Ubuntu 14.04 LTS中的主要程序变化的总结
- error CS0234: 命名空间“XXX”中不存在类型或命名空间名称“UserInfoVm”(是否缺少程序集引用?)
- ORA-12520: TNS:监听程序无法为请求的服务器类型找到可用的处理程序解
- 《Arduino家居安全系统构建实战》——1.4 那么,如何知道程序有效?
- Visual C# 2010入门经典》一1.4 编写第一个程序
- 微信小程序用户数据解密
- 【Redis数据结构 List 类型】List 类型生产中的应用 消息队列、排行榜、老干妈的朋友圈、监控程序的实现
- 【微信小程序】text和rich-text组件的基本使用
- 基于Python实现的微信小程序校园导航系统 | Python第一课环境篇 | Hellow World 程序 | 不同环境下搭建Python编程环境
- 关于用飞信框架运行net程序-用批处理运行
- 学习Android之第六个小程序新浪微博(二)(ListView和TabActivity)