HLJ 发布于
2018-10-19 10:55:20

判断字符串、数组、对象的数据类型

上一篇文章:

JavaScript 延迟加载

下一篇文章:

java生成随机IP

var str1=new String('str1');
var str2='str2';
console.log(typeof str1);//object
console.log(typeof str2);//string
console.log(str1 instanceof String);//true
console.log(str2 instanceof String);//false
console.log(str1.constructor==String);//true
console.log(str2.constructor==String);//true

var a = ['hello','world'];
console.log(typeof a);//object
console.log(a.toString());//hello,world
console.log(Object.prototype.toString.call(a));//[object Array]
console.log(Array.prototype.isPrototypeOf(a));//true
console.log(Array.isArray(a));//true
console.log(a instanceof Array);//true
console.log(a instanceof Object);//true
console.log(a.constructor==Array);//true
console.log(a.constructor==Object);//false

var b = {'hello':'world'};
console.log(typeof b);//object
console.log(b.toString());//[object Object]
console.log(Object.prototype.toString.call(b));//[object Object]
console.log(Object.prototype.isPrototypeOf(b));//true
console.log(b instanceof Object);//true
console.log(b.constructor==Object);//true
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-10-19/263.html
最后生成于 2023-06-18 18:31:06
上一篇文章:

JavaScript 延迟加载

下一篇文章:

java生成随机IP

此内容有帮助 ?
0