0

I want to convert an array to an array of arrays.

For example if my array is:

a = [1,2,3,4,5,6]

I want:

b = [[1,2],[3,4],[5,6]]

How can I do this?

5
  • 2
    you've already did it, no? Commented Sep 11, 2013 at 12:05
  • I dont understand your question? Commented Sep 11, 2013 at 12:07
  • this is the way to create a multidimensional arrays in JS: b= [[1,2],[3,4],[5,6]] , jsfiddle.net/cherniv/Wwwxm Commented Sep 11, 2013 at 12:08
  • from a to b. I have to convert to array like b??I mean it should be convert to tupple array Commented Sep 11, 2013 at 12:10
  • thank you Felix, yes its right Commented Sep 11, 2013 at 12:25

1 Answer 1

2
function Create2DArray(rows) {
  var arr = [];

  for (var i=0;i<rows;i++) {
     arr[i] = [];
  }

  return arr;
}
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.