
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.63 KB | hits: 12 | expires: Never
Convert array to string in NodeJS
var aa = new Array();
aa['a'] = 'aaa';
aa['b'] = 'bbb';
console.log(aa.toString());
var aa = [];
// these are now properties of the object, but not part of the "array body"
aa.a = "A";
aa.b = "B";
// these are part of the array's body/contents
aa[0] = "foo";
aa[1] = "bar";
aa.toString(); // most browsers will say "foo,bar" -- the same as .join(",")
> a = [1,2,3]
[ 1, 2, 3 ]
> a.toString()
'1,2,3'
> var aa = {}
> aa['a'] = 'aaa'
> JSON.stringify(aa)
'{"a":"aaa","b":"bbb"}'
console.log(aa.toString());
console.log(aa.join(' and '));
console.log(aa)
JSON.stringify(aa)