Is there anyway to know specific type of javascript variable
本问题已经有最佳答案,请猛点这里访问。
我的变量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var data = [ { id: 1, name:"John", sex:"M", maritalStatus:"M", dob:"01-01-1990", title:"Software Engineer", address:"VN", phoneNumber:"(123) 456-7890", email:"[email protected]" } ]; var data = [ ["1","John","M","M","1990","Software Engineer","[email protected]","(123) 456-7890"], ]; |
有没有办法知道他们的类型。我用的是
可以使用Objist.Trimest.toStRew()调用(对象)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | var data = { id: 1, name:"John", sex:"M", maritalStatus:"M", dob:"01-01-1990", title:"Software Engineer", address:"VN", phoneNumber:"(123) 456-7890", email:"[email protected]" }; console.log(Object.prototype.toString.call(data) ); //[object Object] var data2 = [ { id: 1, name:"John", sex:"M", maritalStatus:"M", dob:"01-01-1990", title:"Software Engineer", address:"VN", phoneNumber:"(123) 456-7890", email:"[email protected]" } ]; console.log(Object.prototype.toString.call(data2) ); //[object Array] var data1 = [ ["1","John","M","M","1990","Software Engineer","[email protected]","(123) 456-7890"], ]; console.log(Object.prototype.toString.call(data1) );//[object Array] |
由于数据是一个数组,因此
编辑:
在该答案的注释中澄清后,