I want to convert an array to string in NodeJS.
var aa = new Array();
aa[\'a\'] = \'aaa\';
aa[\'b\'] = \'bbb\';
console.log(aa.toString());
<
toString
is a method, so you should add parenthesis ()
to make the function call.
> a = [1,2,3]
[ 1, 2, 3 ]
> a.toString()
'1,2,3'
Besides, if you want to use strings as keys, then you should consider using a Object
instead of Array
, and use JSON.stringify
to return a string.
> var aa = {}
> aa['a'] = 'aaa'
> JSON.stringify(aa)
'{"a":"aaa","b":"bbb"}'