I want to convert an array to string in NodeJS.
var aa = new Array();
aa['a'] = 'aaa';
aa['b'] = 'bbb';
You're using an
If you are going to continue with an array, realize that
toString() will join all the numbered properties together separated by a comma. (the same as
b will not come up using this method because they are not in the numeric indexes. (ie. the "body" of the array)
Object, so you can add and delete properties on it like any other object. So for an array, the numbered properties (they're technically just strings under the hood) are what counts in methods like
.join(), etc. Your other properties are still there and very much accessible. :)
Read Mozilla's documentation for more information about Arrays.
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 = "foo"; aa = "bar"; aa.toString(); // most browsers will say "foo,bar" -- the same as .join(",")