Executes the provided callback for every element in the sequence.
Type of elements within the source iterable.
source
The source iterable.
Callback invoked for each element; receives the element and its zero-based index.
Enumeration starts immediately. Avoid mutating the underlying collection while iterating.
const numbers = [1, 2, 3];forEach(numbers, (x, i) => console.log(`Index ${i}: ${x}`));// Index 0: 1// Index 1: 2// Index 2: 3 Copy
const numbers = [1, 2, 3];forEach(numbers, (x, i) => console.log(`Index ${i}: ${x}`));// Index 0: 1// Index 1: 2// Index 2: 3
Executes the provided callback for every element in the sequence.