阅读:9146 次 编辑日期:2015-06-29
var arr = [8, 10, 13, 10, 8, 1, 5]; function logger(element, index, array) { console.log("The value of the element at index " + index + " is " + element); } arr.forEach(logger); >>>The value of the element at index 0 is 8 >>>The value of the element at index 1 is 10 >>>The value of the element at index 2 is 13 >>>The value of the element at index 3 is 10 >>>The value of the element at index 4 is 8 >>>The value of the element at index 5 is 1 >>>The value of the element at index 6 is 5