1

Probably a simple Jquery syntax question, yet I failed to do it:

I have an array of arrays, like

 n = [[1,2,3], [4,5,6], [7,8,9]]

But I'd like to change it to

 m = [1,2,3,4,5,6,7,8,9]

So I think in other words I want to go from an array of arrays to an array of single 'elements'.

How would I do that?

I tried $.merge(n) but it didn't work as I wanted.

mukesh krishnan
  • 353
  • 1
  • 6
  • 20
ben_aaron
  • 1,504
  • 2
  • 19
  • 39

1 Answers1

3

You don't need to use jQuery for everything.

var n = [[1,2,3], [4,5,6], [7,8,9]];

var result = [];
for (i = 0; i < n.length; i++) {
    result = result.concat(n[i]);
}
Matthew
  • 160
  • 9