JS中的forEach、$.each、map方法推荐

js循环数组各种方法

1
for (var i = 0; i < myStringArray.length; i++) {
alert(myStringArray[i]);
//Do something
}

Array.prototype.foo = "foo!";
var array = ['a', 'b', 'c'];

for (var i in array) {
alert(array[i]);
}

for(var i in this.$GLOBAL_DETAIL.album_photo_ids){if(this.$GLOBAL_DETAIL.album_photo_ids[i] == "3487675024077108") alert(this.$GLOBAL_DETAIL.album_photo_ids[i]);}

[1,2,3,4].map( function(item) {
alert(item);
})

var x = [1,2,3,4].map( function(item) { return item * 10; } );

// And now x is [10,20,30,40]

var myStringArray = [ "Hello", "World" ]
var len = myStringArray.length
for (var i=0; i if (i in myStringArray) {
var s = myStringArray[i];
... do something with s ...
}
}

你可能感兴趣的:(JS中的forEach、$.each、map方法推荐)