Without knowing the keys of a JavaScript Object
, how can I turn something like…
var obj = { param1: 'something', param2: 'somethingelse', param3: 'another' } obj[param4] = 'yetanother';
…into…
var str = 'param1=something¶m2=somethingelse¶m3=another¶m4=yetanother';
…?
Advertisement
Answer
var str = ""; for (var key in obj) { if (str != "") { str += "&"; } str += key + "=" + encodeURIComponent(obj[key]); }
Example: http://jsfiddle.net/WFPen/