js 循环 js创建数组

 

循环

for (var i = 0; i < myArray.length; i++) {
    console.log(myArray[i]);
};

 

for (var arr in myArray ) {
    console.log(arr);
};

 

 $.each(myObject,function(i){
    console.log(myObject[i]);
 });

 

$.each(myArray,function(i,item){
    console.log(item[0]);
 });

 

 

js创建数组

//方法一
var arr1 = [1,3,5,7,9];
document.write(arr1[2] + '<br>');

//方法二
var arr2 = new Array(2,4,6,8,10);
document.write(arr2[3] + '<br>');

//方法三
var arr3 = new Array(3);//固定数组长度为3
arr3[0] = 1;
arr3[1] = 2;
arr3[2] = 3;
document.write(arr3[2] + '<br>');

 

posted @ 2017-06-12 09:39  wdmiye  阅读(9760)  评论(0编辑  收藏  举报