Advertisement
Guest User

Untitled

a guest
Oct 26th, 2012
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //create myData object as shown in question
  2. myData = {};
  3. myData[1] = 'hello';
  4. myData[2] = 'goodbye';
  5. myData[3] = {};
  6. myData[3][1] = 'sub1';
  7. myData[3][2] = 'sub2';
  8. myData[3][3] = 'sub3';
  9.  
  10. //create config object for use with source code
  11. config = {};
  12. config.data = myData;
  13.  
  14. //execute source code snippet
  15.  
  16. var pairs = [];
  17. for (var key in config.data) {
  18.     if (config.data.hasOwnProperty(key)) {
  19.         pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(config.data[key]));
  20.     }
  21. }
  22. var data = pairs.join("&");
  23.  
  24. //
  25. console.log(data);
  26.  
  27. //result
  28. 1=hello&2=goodbye&3=%5Bobject%20Object%5D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement