Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to split the array which contains 20 elements into 10 elements of 2 arrays. I am using jQuery, any easy possible way to do it?

1 Answer

0 votes
by (26.7k points)

You can use plain JavaScript to achieve this:

var a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

var b = a.splice(0,10);

//a is now [11,12,13,14,15];

//b is now [1,2,3,4,5,6,7,8,9,10];

Also, you can loop through this, as per your requirement.

var a = YOUR_ARRAY;

while(a.length) {

    console.log(a.splice(0,10));

}

I hope this will help.

Want to become a Java Expert? Join Java Course now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Tutorial :

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 17, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...