_.each 函式接受一個陣列或一個物件,一個 iteratee 函式和一個可選的 context 物件,iteratee 函式被呼叫一次並且為每個陣列項呼叫 iteratee 函式提供 3 個引數

item - The current iterated object (or value if an object was passed)
i - The index of the iterated object (or key if an object was passed)
list - A reference to the original array/list (the object that was passed)

例 1:

_.each(["hello", "underscore"], function(item, i, list) {
    alert(item)
});

上面的例子將顯示 2 個警報,第一個顯示 hello,第二個顯示 world

例 2:

_.each({one: 1, two: 2, three: 3}, (value, key, object) => 
    console.log(JSON.stringify(object));
);

此示例將記錄物件的字串化版本 3 次。

.each 是一個終端操作,與其他中間函式(map,pluck,values 等)不同,你不需要在 iteratee 函式體內返回。