我很抱歉这含糊不清,并且它不是很好的代表,因为我对JavaScript感到生疏,但是我有一个onclick事件,它会更改组合到数组中的三个元素的值
one = "one"
two = "two"
three = "three"
my_arr = [one, two, three]
而不是替换现在正在发生的arr,我想将新值push
放置到数组的末尾。
我也想创建一个对象数组,以便如果新值是
one = "four"
two = "five"
three = "six"
输出为
arr = [
["one", "two", "three"],
["four", "five", "six"]
]
对不起,我无法完全复制点击事件,希望这足以回答我的问题!
您可以使用Array.prototype.push()
。例如