val is a parameter, and a value is passed every time you click, but the array does not accumulate. I don’t know why.
Because the array you accumulate is new every time, arr is reassigned to ['s', 'd'] every time.
arr
['s', 'd']
Just define var arr = [] outside the current function, similar to this:
var arr = ['s', 'd'] function addArr(val){ arr.push(val) }
Because the array you accumulate is new every time,
arr
is reassigned to['s', 'd']
every time.Just define var arr = [] outside the current function, similar to this: