gpt4 book ai didi

php - JavaScript - 赋值 - 数组的数组

转载 作者:可可西里 更新时间:2023-10-31 22:47:07 24 4
gpt4 key购买 nike

var a = new Array();
var b = new Array();
var c = [a,b];

var str = 'hello,world,nice,day';
for(var i = 0; i < c.length; i++){
c[i] = str.split(',');
}

执行后我想要:

c = [a, b];
a = ['hello', 'world', 'nice', 'day'];
b = ['hello', 'world', 'nice', 'day'];

但我真的有:

c = [['hello', 'world', 'nice', 'day'], ['hello', 'world', 'nice', 'day']];
a = [];
b = [];

我能修好吗?

更新:雷诺斯的决定真是太好了。谢谢。

最佳答案

for(var i = 0; i < c.length; i++){
c[i].push.apply(c[i], str.split(','));
}

关于php - JavaScript - 赋值 - 数组的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8014584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com