Array.prototype.forEachintermediateconst log = []
[1, 2, 3].forEach(n => log.push(n * 2))
log // β [2, 4, 6]Use forEach() when you need side effects like pushing to another array or calling an API.
The forEach callback receives three arguments: (value, index, array). You can use the index to mutate elements in-place by writing back to array[index].
Challenge: Implement multiplyInPlace(arr, factor) that multiplies each element in the array by factor using forEach.
const arr = [1, 2, 3]
multiplyInPlace(arr, 2)
// arr is now [2, 4, 6]