javascript - js array accumulation problem
phpcn_u1582
phpcn_u1582 2017-06-26 10:58:45
0
2
931


val is a parameter, and a value is passed every time you click, but the array does not accumulate. I don’t know why.

phpcn_u1582
phpcn_u1582

reply all(2)
typecho

Because the array you accumulate is new every time, arr is reassigned to ['s', 'd'] every time.

Peter_Zhu

Just define var arr = [] outside the current function, similar to this:

var arr = ['s', 'd']

function addArr(val){
    arr.push(val)
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template