3

I have huge array and need to split it into small array so that I can run it faster. I have array look like this:

var callUrls = ['url1','url2','url3','url4','url5','url6','url7','url8','url9','url10'];

And I want to split it like this:

var callUrls = [
    [url1, url2, url3, url4, url5],
    [url6, url7, url8, url9, url10]
];

How can I do that in js? Thanks in advance

7
  • 1
    Why would it run faster if it was split? What do you want to do? Commented Dec 7, 2015 at 15:35
  • What is the use case where you are assuming that a giant array of arrays will be "faster" than a giant array? I would re-evaluate that assumption before you go through the trouble. Commented Dec 7, 2015 at 15:35
  • @SergeyBelyakov javascript Commented Dec 7, 2015 at 15:36
  • You haven't given a use case for this. On what condition are you splitting this array? Half? Specific index value? We need more information, as this question is too broad. Commented Dec 7, 2015 at 15:36
  • @SergeyBelyakov array_chunk in JavaScript?? Commented Dec 7, 2015 at 15:37

1 Answer 1

1

Try like this

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.