我有大量数组,需要将其拆分为小数组,以便我可以更快地运行它。 我的数组看起来像这样:
var callUrls = ['url1','url2','url3','url4','url5','url6','url7','url8','url9','url10'];
我想把它分开:
var callUrls = [
[url1, url2, url3, url4, url5],
[url6, url7, url8, url9, url10]
];
我怎样才能在js中这样做?提前致谢
答案 0 :(得分:1)
试试这个
var callUrls = ['url1','url2','url3','url4','url5','url6','url7','url8','url9','url10'];
var n=5;
var temp=[];
for(var i=0;i<callUrls.length;i+=n)
temp.push(callUrls.slice(i,i+n));
console.log(temp);
的 JSFIDDLE 强>