gpt4 book ai didi

javascript - 将数组压入数组

转载 作者:行者123 更新时间:2023-11-28 16:03:08 25 4
gpt4 key购买 nike

如何使用 Javascript 推送数组中的数组

我知道只能推送普通数组,例如...

var arr = [];
arr.push(['one','two','three']);

那就是..

array(
'one',
'two',
'three'
)

但是呢?怎么这样推...

array(
array(
'one',
'one_two'
),
'two',
'three'
)

最佳答案

这就是您已经在做的事情。

此代码创建一个数组:

var arr = [];
arr.push('one','two','three'); // push three items

即结果相同:

var arr = ['one','two','three'];

这段代码创建了一个锯齿状数组(数组中的数组):

var arr = [];
arr.push(['one','two','three']); // push one item that is an array

即结果相同:

var arr = [
['one','two','three']
];

关于javascript - 将数组压入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209241/

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