简体   繁体   English

将数组推送到js中的另一个数组中?

[英]Push array inside another array in js?

I have a multidimensional array in js that I want to fill using a for bucle.我在 js 中有一个多维数组,我想使用 for bucle 填充它。

To do this, I use this code:为此,我使用以下代码:

var array = [];
var aux = [];
for(i=0;i<10;i++){
    aux = [i,i+1,i+2];
    array.push({
       name:i,
       data:aux
    });

}

The issue is that the name is changed but the data key is overwritten, so I think that I have to push the data too, but don't know how.问题是名称已更改但数据键被覆盖,因此我认为我也必须推送数据,但不知道如何。

Maybe something like that也许是这样的

const array = [];
for (i = 0; i < 10; i++) {
    const aux = [];
    const quantity = i + 3;
    for (j = i; j < quantity; j++) {
        aux.push(j);
    }
    array.push({ name: i, data: aux });
}

Let me know if need some help or change如果需要帮助或改变,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM