1-声明一个一维数组 数组名为 arr
var arr = [1,2,3,4];
console.log(arr);
2- 声明一个二维数组 数组名为arr1
var arr1 = [[1],[2,3],[4,5,6]];
console.log(arr1);
3- 遍历二维数组
for(var i = 0; i < arr1.length;i++){
for(var j=0;j<arr1[i].length;j++){
document.write(arr1[i][j]);
}
}
4- 声明一个对象 名为 per
var per = new Object();
5- 声明一个对象 名为 per1
var per1 = {name:"九妹妹",sex:"男",age:16};
console.log(per1);
6- 遍历对象信息
for(var 变量 in 对象){}
for(var a in per1){
console.log(a);
console.log(per1[a]);
}
声明一个数组名为 arr的数组
var arr = [1,2,3,4];
console.log(arr);
声明一个数组名为array 数组 二维数组
var array = [[1,2],[3,4],[5,6]];
console.log(array);*/
var array = [[1,2],[3,4],[5,6]];
遍历出数组中的每一个数据
for(var i = 0; i < array.length;i++){
console.log(array[i]);
for(var j = 0;j < array[i].length;j++){
console.log(array[i][j]);
}
}
console.log(typeof(array));
遍历数组对象表格
<script>
var array1 = [
{name:"张三",sex:"女",age:88},
{name:"李四",sex:"妖",age:99},
{name:"王五",sex:"未知",age:250}
];
document.write('<table border=1 width=300 height=200>');
document.write('<tr>');
document.write('<th>name</th>');
document.write('<th>sex</th>');
document.write('<th>age</th>');
document.write('</tr>');
for(var i = 0; i < array1.length; i++){
console.log(array1[i]);
document.write('<tr>');
for(var j in array1[i]){
document.write('<td align="center">'+array1[i][j]+'</td>');
}
document.write('</tr>');
}
document.write('</table>');
</script>