当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 判断字符串、数组、对象的数据类型

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

2018年08月22日  | 移动技术网IT编程  | 我要评论
 1 var str1=new string('str1');
 2 var str2='str2';
 3 console.log(typeof str1);//object
 4 console.log(typeof str2);//string
 5 console.log(str1 instanceof string);//true
 6 console.log(str2 instanceof string);//false
 7 console.log(str1.constructor==string);//true
 8 console.log(str2.constructor==string);//true
 9 
10 var a = ['hello','world'];
11 console.log(typeof a);//object
12 console.log(a.tostring());//hello,world
13 console.log(object.prototype.tostring.call(a));//[object array]
14 console.log(array.prototype.isprototypeof(a));//true
15 console.log(array.isarray(a));//true
16 console.log(a instanceof array);//true
17 console.log(a instanceof object);//true
18 console.log(a.constructor==array);//true
19 console.log(a.constructor==object);//false
20 
21 var b = {'hello':'world'};
22 console.log(typeof b);//object
23 console.log(b.tostring());//[object object]
24 console.log(object.prototype.tostring.call(b));//[object object]
25 console.log(object.prototype.isprototypeof(b));//true
26 console.log(b instanceof object);//true
27 console.log(b.constructor==object);//true

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网