jQuery.each( collection, callback(indexInArray, valueOfElement) )

collectionThe object or array to iterate over.

callback(indexInArray, valueOfElement)The function that will be executed on every object.


each 를 쓸때 callback function 에  첫번째 파라미터는 index 값이다. i++ .. 과 같다고 봐도 된다.

---------------------------------

from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach

Syntax

array.forEach(callback[, thisArg])

Parameters

callback
Function to execute for each element.
thisArg
Object to use as this when executing callback.


<script>

var arr = ['a','b','c','d','e'];

// item:a/index:0

arr.forEach(function (item,index) {
    alert('item:'+item+'/index:'+index);

});

</script>


+ Recent posts