1

I have an array like

var array = ['a','b','c','d','e','f','g','h','i'];

I need to display based on the following 2 conditions.

1) If I pass an array to a function like, function(array,2) then the array should display like [[a,b],[c,d],[e,f],[g,h],[i]].

2) If I pass an array to a function like, function(array,3) then the array should display like [[a,b,c],[d,e,f],[g,h,i]].

How this can be achievable using javascript? Please help me, thanks in advance.

Eddie
  • 26,593
  • 6
  • 36
  • 58
User
  • 385
  • 8
  • 21
  • Please post an example of the code you have to achieve the desired result. It's doable by iterating over initial array and pushing data to the result array. – Vitalii Chmovzh Feb 11 '18 at 17:00
  • Looks like the answer you're looking for is in this thread: https://stackoverflow.com/questions/8495687/split-array-into-chunks – Alex Dovzhanyn Feb 11 '18 at 17:02

0 Answers0