为数组的每一项调用一个函数
语法:
myArray.each(fn[, bind]);
参数:
- fn - (function) 数组的每一项要执行的函数,此函数传递数组的项和它的索引。
- bind - (object, optional) 在上面的数组里面用作this的对象
变量: fn
语法:
fn(item, index, array)
参数:
- item - (mixed) 数组的当前项。
- index - (number) 当前数组项在数组的索引,当时一个对象时,它是对象的键而不是索引。
- object - (mixed) 数组本身。
举例:
['apple', 'banana', 'lemon'].each(function(item, index){
console.log(index + " = " + item);
});