Home › Forums › JavaScript › serialize 2 dimensional array › Reply To: serialize 2 dimensional array
November 16, 2016 at 10:52 am
#247928
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:
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'