<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/*
for-in语句
格式: for(var 变量名 in 遍历目标){
}
作用: (1)遍历数组元素
(2)遍历对象的所有属性数据
注意: (1)遍历数组时,得到的元素下标;
(2)使用对象遍历时,遍历的是对象的属性名。
document.write("<hr/>");
var arr=[12,13,19,15,16];
for(var index in arr){
document.write(arr[index]+",");
}
document.write("<hr/>");
var arr=[12,13,19,15,16];
for(var index=0;index<arr.length;index++){
document.write(arr[index]+",");
}
document.write("<hr/>");
*/
function Person(id,name){
this.id=id;
this.name=name;
}
var p=new Person(110,"狗娃");
for(var property in p){
document.write(p[property]+",");
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>for-in语句</title>
</head>
<body>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/*
for-in语句
格式: for(var 变量名 in 遍历目标){
}
作用: (1)遍历数组元素
(2)遍历对象的所有属性数据
注意: (1)遍历数组时,得到的元素下标;
(2)使用对象遍历时,遍历的是对象的属性名。
document.write("<hr/>");
var arr=[12,13,19,15,16];
for(var index in arr){
document.write(arr[index]+",");
}
document.write("<hr/>");
var arr=[12,13,19,15,16];
for(var index=0;index<arr.length;index++){
document.write(arr[index]+",");
}
document.write("<hr/>");
*/
function Person(id,name){
this.id=id;
this.name=name;
}
var p=new Person(110,"狗娃");
for(var property in p){
document.write(p[property]+",");
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>for-in语句</title>
</head>
<body>
</body>
</html>