Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript serialize 2 dimensional array Reply To: serialize 2 dimensional array

#247928
Shikkediel
Participant

I’m not so sure either but it turns out to be quite an interesting question, going into the possibilities of JS methods. This one’s pretty neat too:

Demo

var result = a.map(function(it) {
  return it.join('&');
});

result = result.join('&');

So with the first step and .map a single new array is created while looping over each element (it), looking like this:

['val1&val2&val3','val3&val4&val5','val9&val8&val7']

Then that array is also turned into a string with join, using & as the separator character:

'val1&val2&val3&val4&val5&val6&val9&val8&val7'