简体   繁体   English

如何使用两个不同的数组或单个数组创建 2D

[英]how to create 2D using two different array or single array

I want output like this我想要这样的 output

items = [['red', 'blue', 'green'], ['small', 'medium', 'large']]; items = [['red', 'blue', 'green'], ['small', 'medium', 'large']];

i have array item which has value items =['red', 'blue', 'green','small', 'medium', 'large']我有数组项,其值为items =['red', 'blue', 'green','small', 'medium', 'large']

if mutation is not a problem, then you might remove initial array until you move them 3 by 3 into new one.如果突变不是问题,那么您可能会删除初始数组,直到将它们 3 3 移动到新数组中。

const items = ['red', 'blue', 'green', 'small', 'medium', 'large'];

let itemList = [];

while (items.length > 0) {
    itemList.push(items.splice(0, 3))
}

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

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