I am currently working on a forEach() function that increments an array by one for each iteration.
The problem I am facing is that whenever I try to display the value of the number
variable in the browser's console, it only shows me the final state instead of the current one. Is this inconsistency normal or could there be something fundamentally wrong with my code?
Here is the console output for reference
let array =
[
{
"id":1,
},
{
"id":2,
},
{
"id":3,
}
]
let number = [0]
array.forEach(() => {
number[0] += 1
console.log(number)
})