You're using an Array like an "associative array", which does not exist in JavaScript. Use an Object ({}) instead.

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 .join(",")).

Properties like a and b will not come up using this method because they are not in the numeric indexes. (ie. the "body" of the array)

In JavaScript, Array inherits from 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 .toString(), .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[0] = "foo";
aa[1] = "bar";

aa.toString(); // most browsers will say "foo,bar" -- the same as .join(",")
Answer from Dominic Barnes on Stack Overflow
🌐
Webslesson
webslesson.info › 2023 › 08 › how-to-convert-array-to-string-in-nodejs.html
How to convert Array to String in Node.js | Webslesson
August 18, 2023 - Here's how you can use it: const ... console.log(result); // Output: "apple, banana, orange" JavaScript arrays inherit a default toString() method that converts an array to a string by joining the elements with commas....
🌐
ReqBin
reqbin.com › code › javascript › ot8wzla9 › javascript-array-to-string-example
How do I convert array to string in JavaScript?
November 21, 2023 - You can also create a multiline string, check if it starts or ends with another string, and get the length of a string. In JavaScript, you can convert an array to a string using the Array.join(separator) and array.toString() methods.
🌐
CodingNomads
codingnomads.com › javascript-array-to-string-conversion
JavaScript Array-String Conversion
Whether you're concatenating array elements into a user-friendly string or breaking down a string into an array for detailed processing, these methods are useful in any JavaScript toolkit. The .join() Array method is used to convert an array ...
🌐
sebhastian
sebhastian.com › javascript-array-string
Convert a JavaScript array to string | sebhastian
February 1, 2023 - To easiest way to convert a JavaScript array to string is to use the built-in Array method called toString().
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_array.asp
JavaScript Array toString() Method
The toString() method returns a string with array values separated by commas.
🌐
Medium
medium.com › @louistrinh › converting-arrays-to-strings-in-javascript-4d1bbea80c20
Converting Arrays to Strings in JavaScript | by Louis Trinh | Medium
November 20, 2024 - The built-in toString() method on Arrays converts each element to a String and joins them with commas.
Find elsewhere
🌐
Tabnine
tabnine.com › home › array to string in javascript
Array to String in JavaScript - Tabnine
July 25, 2024 - This code takes a mixed array and returns the comma-delimited string representation, converting each data type in turn into a string.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › array-tostring
Array toString() in JavaScript - Mastering JS
December 8, 2021 - To convert an array to a string in JavaScript, you can use the toString() method.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-array-to-string-in-javascript
Convert Array to String in JavaScript - GeeksforGeeks
July 23, 2025 - The JSON.stringify() method converts an array including even the nested arrays and objects to a JSON string.
🌐
Scaler
scaler.com › home › topics › array to string in javascript
Array to String in JavaScript - Scaler Topics
January 8, 2024 - In order to convert an array into a string in Javascript, we simply apply the toString() method on the given array, and we get a stringified version of our array.
🌐
YouTube
youtube.com › watch
JavaScript Basics - How To Convert An Array Into A String - YouTube
In this tutorial I'll show you how to convert an array into a string in JavaScript.-------------------------------------------------------------------All my ...
Published: November 18, 2024
🌐
Stack Overflow
stackoverflow.com › questions › 61657766 › how-to-convert-an-array-to-string
javascript - How to convert an array to string - Stack Overflow
Convert javascript array to string (13 answers) Closed 6 years ago. I have an array like this - var arr = ['This', 'is', 'array'] I want the string output like this - "This is array" javascript · arrays · Share · Short permalink to this question · Improve this question ·
🌐
YouTube
youtube.com › watch
How to convert Array to String in Node.js - YouTube
In this Node.js video tutorial, we will show you how can we convert array to string in Node.js programming. Under this video tutorial, we will discuss how di...
Published: August 18, 2023
🌐
Medium
medium.com › konsole-blog › 5-ways-to-convert-array-to-string-in-javascript-f6a92ac5788f
5 ways to convert Array to String in Javascript | by David Petrosyan | Konsole.blog | Medium
May 23, 2022 - Unlike the array.toString() method, you can use the array.join() method to convert the array into a string with or without commas.