This is similar to the forEach method. The forEach method, as is known, can take the following parameters (callback[, thisArg]) . Here is a function that is analogous to this method.
How to add thisArg parameter (Optional parameter. Value used as this when calling the callback function)?
var array = [1, 2, 3, 4, 5, 6]; console.log(customForEach(array, func)); function customForEach(src, callback) { for (var i = 0; i < src.length; i++) { callback(src[i], i, src); } } function func(item, i, arr) { console.log(i + ' Элемент: ' + item + '(массив ' + arr + ')'); }
console.log(customForEach(array, func));- What do you expect to see in the console? - Igor