作者:雷宠专业摄影工作室 | 来源:互联网 | 2023-05-19 07:08
Ihaveanarraywithavariablelengththatisgreaterthan3andcanbeoddoreven.我有一个可变长度大于3的数组
I have an array with a variable length that is greater than 3 and can be odd or even.
我有一个可变长度大于3的数组可以是奇数或偶数。
For example: var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
例如:var arr =[a,b,c,d,e,f,g,h,'我',' j '];
Now I want to split that array into halves.
现在我想把这个数组分成两半。
['a', 'b', 'c', 'd', 'e']
and ['f', 'g', 'h', 'i', 'j']
[a,b,c,d ',' e ']和[‘f’、‘g’、‘h’,‘我’,' j ']
Next I want to split those chunks into halves and to keep doing that until the chunks have a length of 3 or 2.
接下来,我要把这些块分割成两半,直到这些块的长度是3或2。
Finally I want to store those chunks in a new array.
最后,我想将这些块存储在一个新的数组中。
var newarr = [['a','b','c'],['d','e'],['f','g','h'],['i','j']];
var newarr =[[' a ',' b ',' c '],[' d ',' e '],[' f ',' g ',' h '],['我',' j ']];
How would I do this?
我该怎么做呢?
2 个解决方案