forEach()
Обновлено: 09.03.2023
Приклад
Викликає функцію для кожного елемента у фруктах:
const fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);
Визначення та використання
Метод forEach()викликає функцію для кожного елемента в масиві.
Метод forEach()не виконується для порожніх елементів.
Синтаксис
array.forEach(function(currentValue, index, arr), thisValue)
Параметри
| function() | Required. A function to run for each array element. |
| currentValue | Required. The value of the current element. |
| index | Optional. The index of the current element. |
| arr | Optional. The array of the current element. |
| thisValue | Optional. Default "undefined". A value passed to the function as its "this" value. |
Повернене значення
| невизначений |