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
If you're dealing with more complex data, JSON.stringify() can be invaluable. Lastly, custom formatting with map() and join() provides flexibility for specific output formats. Remember to consider your use case and the desired format of the output when choosing the appropriate method for converting arrays to strings in your Node.js applications.
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_array.asp
JavaScript Array toString() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
Array.prototype.join recursively converts each element, including other arrays, to strings. Because the string returned by Array.prototype.toString (which is the same as calling join()) does not have delimiters, nested arrays look like they are flattened.
🌐
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
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-converting-arrays-to-strings
Converting Arrays to Strings in JavaScript | DigitalOcean
December 5, 2019 - Even with the modern niceties, it’s still good to know how to convert an array to a string for those times when you need to massage an array into another format, or want to do something more than simply comma separating the values (the default behavior). No special tools required. You can hack along in either your web browser’s console or using the Node.js REPL.
🌐
ReqBin
reqbin.com › code › javascript › ot8wzla9 › javascript-array-to-string-example
How do I convert array to string in JavaScript?
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.
🌐
sebhastian
sebhastian.com › javascript-array-string
Convert a JavaScript array to string | sebhastian
February 1, 2023 - To convert an array of objects into a string, you need to use the JSON.stringify method as shown below:
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-an-array-to-a-string-in-javascript
How to Convert an Array to a String in JavaScript?
Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
🌐
Scaler
scaler.com › home › topics › array to string in javascript
Array to String in JavaScript - Scaler Topics
January 8, 2024 - There is no direct method present to do so. But if we take a closer look at the given scenario, then we will notice that the string contains all the elements of the array, and if we simply combine all the given elements into a single array, ...
🌐
Codedamn
codedamn.com › news › javascript
How to convert a JavaScript array to a string (with examples)?
October 27, 2022 - JavaScript is a scripting language that was initially built to add interactivity to web pages but now it has become the heart of web development. Arrays and strings are one of the most widely used concepts in JavaScript today. This article explains how to convert JavaScript array to stings along ...
🌐
Futurestud.io
futurestud.io › tutorials › javascript-join-an-array-of-strings-to-a-single-string-value
JavaScript — Join an Array of Strings to a Single String Value
The join method supports an optional, second argument which is used to concatenate the last item to the resulting string. import { Arr } from '@supercharge/arrays' const tags = ['JavaScript', 'Node.js', 'Strings'] Arr.from(tags).join() // 'JavaScript,Node.js,Strings' Arr.from(tags).join(', ') // 'JavaScript, Node.js, Strings' Arr.from(tags).join(', ', ', and') // 'JavaScript, Node.js, and Strings'
🌐
W3Schools
w3schools.com › jsref › jsref_join.asp
JavaScript Array join() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
ReqBin
reqbin.com › code › javascript › jaarxzpl › javascript-string-to-array-example
How do I convert string to array in JavaScript?
You can also convert an array to a string, check if it starts or ends with another string, create a multiline string, and get the length of a string. In JavaScript, an array is a special built-in object that allows multiple elements of different types to be stored in a single variable.