I have a forEach() function that increments an array by one for each iteration.
Issue is that every time I print the number
variable into the browser's console it shows me its last state instead of the current one. Is this an inconsistency or am I doing something terribly wrong?
let array =
[
{
"id":1,
},
{
"id":2,
},
{
"id":3,
}
]
let number = [0]
array.forEach(() => {
number[0] += 1
console.log(number)
})