JavaScript实现一维数组转化为二维数组
时间:2020-12-30 13:31:43|栏目:Python代码|点击: 次
啥也不说了,上代码吧!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <script type="text/javascript"> var num = 4;//每个子数组里的元素个数 var arr = [1,4,5,6,34,34,67,895,2456,87,9,5,23,884,56]; var Arr = new Array(Math.ceil(arr.length/num)); for(var i = 0; i<Arr.length;i++){ Arr[i] = new Array(); for(var j = 0; j<num; j++){ Arr[i][j] = ''; } } for(var i = 0; i<arr.length;i++){ Arr[parseInt(i/num)][i%num] = arr[i]; } console.log(Arr) </script> </head> <body> </body> </html>
栏 目:Python代码
本文地址:http://www.codeinn.net/misctech/38304.html