# Converting an Array to a String in JavaScript

**URL:** <https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502>\
**Category:** General Questions/Help\
**Tags:** js\
**Created:** [22 September 2023 10:43 UTC](https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502 "2023-09-22T10:43:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harwind](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/h/c77e96/32.png) [@harwind](https://forum.devtalk.com/u/harwind)\
**Post date:** [22 September 2023 10:43 UTC](https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502/1 "2023-09-22T10:43:50Z")

</div>

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:

```auto
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:

```auto
"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](https://www.scaler.com/topics/convert-array-to-string-javascript/), but I was unsuccessful. Please help me with this, Thank you.

---

<div class="post-metadata">

**Author:** ![PeterKeyse](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/6f9a4e/32.png) [@PeterKeyse](https://forum.devtalk.com/u/PeterKeyse)\
**Post date:** [24 September 2023 16:54 UTC](https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502/2 "2023-09-24T16:54:04Z")

</div>

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 +’: ’

---

<div class="post-metadata">

**Author:** ![mindriot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mindriot/32/6660_2.png) [@mindriot](https://forum.devtalk.com/u/mindriot)\
**Post date:** [25 September 2023 09:08 UTC](https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502/3 "2023-09-25T09:08:13Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)

---

<div class="post-metadata">

**Author:** ![gulshan212](https://forum.devtalk.com/user_avatar/forum.devtalk.com/gulshan212/32/4971_2.png) [@gulshan212](https://forum.devtalk.com/u/gulshan212)\
**Post date:** [26 September 2023 08:19 UTC](https://forum.devtalk.com/t/converting-an-array-to-a-string-in-javascript/125502/4 "2023-09-26T08:19:32Z")

</div>

Well, you have to use the join method to do what you are looking for.

```auto
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
