Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Convert array to string in NodeJS
  2. var aa = new Array();
  3. aa['a'] = 'aaa';
  4. aa['b'] = 'bbb';
  5.  
  6. console.log(aa.toString());
  7.        
  8. var aa = [];
  9.  
  10. // these are now properties of the object, but not part of the "array body"
  11. aa.a = "A";
  12. aa.b = "B";
  13.  
  14. // these are part of the array's body/contents
  15. aa[0] = "foo";
  16. aa[1] = "bar";
  17.  
  18. aa.toString(); // most browsers will say "foo,bar" -- the same as .join(",")
  19.        
  20. > a = [1,2,3]
  21. [ 1, 2, 3 ]
  22. > a.toString()
  23. '1,2,3'
  24.        
  25. > var aa = {}
  26. > aa['a'] = 'aaa'
  27. > JSON.stringify(aa)
  28. '{"a":"aaa","b":"bbb"}'
  29.        
  30. console.log(aa.toString());
  31.        
  32. console.log(aa.join(' and '));
  33.        
  34. console.log(aa)
  35.        
  36. JSON.stringify(aa)