数据类型:
Undefined Null Boolean String Number Object Reference List Completion
[color=red][size=large]前缀; a b f fn(函数) 整型i 对象 o 正则re 字符串s 变量v[/size][/color]
JS基本数据类型有5个种
string : var xx="few"; alert(typeof(xx)) 结果:string
number: var xx=123;alert(typeof(xx)) 结果:number
boolean:var xx=true;alert(typeof(xx)) 结果:boolean
null:var xx=null;alert(typeof(xx)) 结果:object(比较特殊)
undifined:var xx;alert(typeof(xx)) 结果:undifined
注意 typeof得结果都是 字符串的。
所以如果你要判断变量数据类型: if(typeof(xx)=="变量类型结果")
还有自己定义数据类型
:object 包括数组
对于字符串转数值类型: parseInt() parseFloat() 前提:只有字符类型才能转换否则返回NaN
var aClor=new Array();
aColor[0]="bl ue";
或 var aMap=new Array("china","usa");
alert(aMap.toString() + typeof(aMap.toString()));
或
for(var i in aMap)
document.write(aMap[i]+"<br>");
如果不希望以逗号进行转换后的连接,,则可以用哪个join();用来连接数组项的字符串
document.write(aMap.join()); 等同toString()
aMap.join(""); 不使用连接符
aMap.join("][") 使用“][”
aMap.reverse().toString()
aMap.sort()
aMap.push("xxxx");
aMap.pop()
其他对象:Date Math
BOM brower Object Model
window
document
location
navigator
screen
没有办法预知对象的任何信息 更谈不上使用循环的次数,,可使用for...in语句
for(var i in widow)
document.write(i+"="+window+"<br>");
Undefined Null Boolean String Number Object Reference List Completion
[color=red][size=large]前缀; a b f fn(函数) 整型i 对象 o 正则re 字符串s 变量v[/size][/color]
JS基本数据类型有5个种
string : var xx="few"; alert(typeof(xx)) 结果:string
number: var xx=123;alert(typeof(xx)) 结果:number
boolean:var xx=true;alert(typeof(xx)) 结果:boolean
null:var xx=null;alert(typeof(xx)) 结果:object(比较特殊)
undifined:var xx;alert(typeof(xx)) 结果:undifined
注意 typeof得结果都是 字符串的。
所以如果你要判断变量数据类型: if(typeof(xx)=="变量类型结果")
还有自己定义数据类型
:object 包括数组
对于字符串转数值类型: parseInt() parseFloat() 前提:只有字符类型才能转换否则返回NaN
var aClor=new Array();
aColor[0]="bl ue";
或 var aMap=new Array("china","usa");
alert(aMap.toString() + typeof(aMap.toString()));
或
for(var i in aMap)
document.write(aMap[i]+"<br>");
如果不希望以逗号进行转换后的连接,,则可以用哪个join();用来连接数组项的字符串
document.write(aMap.join()); 等同toString()
aMap.join(""); 不使用连接符
aMap.join("][") 使用“][”
aMap.reverse().toString()
aMap.sort()
aMap.push("xxxx");
aMap.pop()
其他对象:Date Math
BOM brower Object Model
window
document
location
navigator
screen
没有办法预知对象的任何信息 更谈不上使用循环的次数,,可使用for...in语句
for(var i in widow)
document.write(i+"="+window+"<br>");