Even though each function in arr is a closure but all of them are refering to the same reference of i. So whenever i increment, it also affect all elements in arr.
To fix it simply change var i = 0 to let i = 0. since the keyword let works in block scope instead of functional scope in the var keyword. So each i generated in the for loop have their own context.