js如何获取当前对象的类型(number/string/boolean)

2025年02月28日 建站教程

javascript如何利用方法获取当前对象是numberstringboolean等。下面web建站小编给大家详细介绍一下代码!

实例​代码如下:

console.log( typeof '1234' );  //检测数字1234,结果为:string
console.log( typeof 1 );  //检测数字1,结果为:number
console.log( typeof true );   //检测true,结果为:boolean
console.log( typeof false );  //检测false,结果为:boolean
console.log( typeof undefined );  //检测undefined,结果为:undefined
console.log( typeof null );  //检测null,结果为:object
console.log( typeof {} );  // 检测对象,结果为:object
console.log( typeof [] );  //检测数组,结果为:objec

本文链接:http://so.lmcjl.com/news/24016/

展开阅读全文
相关内容