使用数组推送

问题描述 投票:0回答:1

我很抱歉这含糊不清,并且它不是很好的代表,因为我对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"]
]

对不起,我无法完全复制点击事件,希望这足以回答我的问题!

javascript arrays push
1个回答
0
投票

您可以使用Array.prototype.push()。例如

© www.soinside.com 2019 - 2024. All rights reserved.