
harwind
Converting an Array to a String in JavaScript
I have an array of strings in JavaScript, and I need to convert it into a single string with specific delimiter characters between the elements. Here’s a sample array:
let myArray = ["apple", "banana", "cherry", "date"];
I want to convert this array into a single string with a comma and space (", ") between each element. The desired output should look like this:
"apple, banana, cherry, date"
Please send me the JavaScript code I need to do this conversion. If I wish to use a different character or characters between the array components, how can I change the delimiter? I looked for a solution by visiting many sources, but I was unsuccessful. Please help me with this, Thank you.
Most Liked

PeterKeyse
Here’s an example of how I string together the keywords from an JSon array:
Keywords = Data.keywords_and_keyphrases
KeywordString = 'Keywords: ’
for (let i = 0; i < Keywords.length; i++) {
Keyword = Keywords[i]
KeywordString = KeywordString + Keyword + ', ’
}
As you can see they’re separated by a comma + ‘, ’ which could equally be +’: ’

mindriot
In your example you could just do:
myArray.join(“, “);
You can pass any string to the join method as a delimiter. See Array Join method documentation

gulshan212
Well, you have to use the join method to do what you are looking for.
let myArray = ["apple", "banana", "cherry", "date"];
let delimiter = ", "; // You can change this to your desired delimiter
let result = myArray.join(delimiter);
console.log(result);
Thanks
Popular General Dev topics










Other popular topics









Latest in General Dev
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /haskell
- /java
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim