我正在尝试将值插入多维数组,并根据我在本网站其他帖子上看到的代码从中读取值。这是我的数组推送代码。
SelectedWindowGraphs.push([ContainerIDValue,elementID+"chkbox"]);
ContainerIDValue 是一个整数,elementID+"chkbox"是我想要存储在数组中该位置的内容。这是我调试代码时看到的内容:
这不是我想要的。在位置 0,我想要 CUT17chkbox、CUT18chkbox 和 CUT19chkbox。我如何修复我的数组以便我做到这一点?
最佳答案
// initialize an array at that position in case it has not been defined yet
SelectedWindowGraphs[ContainerIDValue] = (SelectedWindowGraphs[ContainerIDValue] ||
[]);
// push the value at the desired position
SelectedWindowGraphs[ContainerIDValue].push(elementID+"chkbox");
关于JavaScript。推送并读取多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51070178/