When JavaScript coerces an array to a string, it actually call: .join(',') on the array. So you're actually going to be getting better performance with .join(',') manually as opposed to leaving it up to the interpreter to notice you're coercing the array. So: x + ',' + y is the fastest, [x, y].join(',') is the best practice(since it makes it easier to modify the behavior), and [x, y] is a tiny bit slower than manually calling .join and can be unreadable at times, but it's more convenient.

Answer from TenorB on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › join
Array.prototype.join() - JavaScript | MDN
The join() method of Array instances creates and returns a new string by concatenating all of the elements in this array, separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
Top answer
1 of 2
23

When JavaScript coerces an array to a string, it actually call: .join(',') on the array. So you're actually going to be getting better performance with .join(',') manually as opposed to leaving it up to the interpreter to notice you're coercing the array. So: x + ',' + y is the fastest, [x, y].join(',') is the best practice(since it makes it easier to modify the behavior), and [x, y] is a tiny bit slower than manually calling .join and can be unreadable at times, but it's more convenient.

2 of 2
5

the short answer: use array.join.

the long answer:

First off, concatenation isn't faster than using array.join(), it's slower. this is because each time you concatenate you destroy two strings and create a new one.

take the following code:

<script>
function concat(){
var txt = '';
for (var i = 0; i < 1000000; i++){
txt =+ i + ',';
}
}

function arr(ar){
var txt = 'asdf' + ar;
}

ar = [];
for (var i = 0; i < 1000000; i++) {
ar.push(i);
}

concat();

arr(ar);

alert('done!');
</script>

and paste it into an html file. Then profile it. On my machine (core i7EE, 16GB RAM, SSD disks, IE9), arr() takes 0ms and concat() takes 12ms. Keep in mind this is over a million iterations (this same test would be quite different on IE6, concat() would take seconds).

Second, concatenation will take the same as array.join when having only two values. So for your example, from a performance perspective, they're both equivalent. if you take the above code and change the 1000000 to 4, both concat and arr take 0ms to execute. this means the difference for your particular flow is either inexistent or so negligible it doesn't show up in a profile.

Third, modern browsers optimize string concatenation using array.join() anyways, so the discussion is probably moot from a performance point of view.

That leaves us with style. Personally, I wouldn't use the first form because I don't like manually concatenating strings (when you've got 2 vars it's rather straightforward, but what if you have 10 vars? that'll make a really long line of code. And what if you receive an array with n values, in comes a for loop). I wouldn't use the second form either because, as pointed out in another answer, the value is coerced to a string, and that means some implicit transformation is going on. The problem here is the implicit part. I know now arrays are joined with a comma when coerced, but what happens if the spec changes, or some genius decides to change the toString implementation of Array.prototype in your codebase? just for fun run this in jsfiddle:

Array.prototype.toString = function() {
return 'not the expected result!';
}

alert([1, 2]);

Can you guess what the answer will be? (the above code will execute the same kind of conversion for the array as your code. coercion via the toString() method)

if you use array.join(','); you'll be futureproofing your code by stating that 1) your array will be joined regardless of the toString implementation and 2) it will be joined with a comma.

🌐
W3Schools
w3schools.com › jsref › jsref_join.asp
JavaScript Array join() Method
cssText getPropertyPriority() ... "Orange", "Apple", "Mango"]; let text = fruits.join(" and "); Try it Yourself » · The join() method returns an array as a string....
🌐
O'Reilly
oreilly.com › library › view › javascript-the-definitive › 0596101996 › re08.html
Array.join( ): concatenate array elements to form a string — ECMAScript v1 - JavaScript: The Definitive Guide, 5th Edition [Book]
August 17, 2006 - join( ) converts each element of an array to a string and then concatenates those strings, inserting the specified separator string between the elements.
Author   David Flanagan
Published   2006
Pages   1018
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › concat
Array.prototype.concat() - JavaScript | MDN
Polyfill of Array.prototype.concat in core-js with fixes and implementation of modern behavior like Symbol.isConcatSpreadable support · es-shims polyfill of Array.prototype.concat · Indexed collections guide · Array · Array.prototype.push() Array.prototype.unshift() Array.prototype.splice() String.prototype.concat() Symbol.isConcatSpreadable · Was this page helpful to you?
🌐
Stack Abuse
stackabuse.com › how-to-concatenate-strings-in-an-array-in-javascript
How to Concatenate Strings in an Array in JavaScript
May 16, 2023 - The concat() function is straightforward - it concatenates two strings. Given an array of entries, we can simply loop through it and concat() each entry onto an empty string and return it:
🌐
daily.dev
daily.dev › home › blog › get into tech › join method javascript: faqs answered
Join Method JavaScript: FAQs Answered
December 22, 2025 - The join() method in JavaScript is an essential tool for converting arrays into strings. This method allows you to specify a separator for the items in the array, defaulting to a comma if none is provided.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › concat-string-array
How to Concatenate Strings in an Array using JavaScript - Mastering JS
JavaScript's join() method is handy for turning elements in an array into a string. JavaScript arrays can contain values of different types. If you only want to concatenate strings, you can filter out non-string values using filter() and typeof ...
Find elsewhere
🌐
CoreUI
coreui.io › answers › how-to-convert-an-array-to-a-string-in-javascript
How to convert an array to a string in JavaScript · CoreUI
September 23, 2025 - Use the join() method to convert an array into a string with custom separators in JavaScript efficiently.
🌐
ReqBin
reqbin.com › code › javascript › 98ugueow › javascript-array-join-example
How do I join array elements in JavaScript?
You can also convert string to array, convert array to JSON, convert array to string, and get a sum of array elements. The array.join(separator) method in JavaScript allows you to concatenate all the elements of an array into a single string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › concat
String.prototype.concat() - JavaScript | MDN
The following example combines strings into a new string. ... const hello = "Hello, "; console.log(hello.concat("Kevin", ". Have a nice day.")); // Hello, Kevin. Have a nice day. const greetList = ["Hello", " ", "Venkat", "!"]; "".concat(...greetList); // "Hello Venkat!" "".concat({}); // "[object Object]" "".concat([]); // "" "".concat(null); // "null" "".concat(true); // "true" "".concat(4, 5); // "45"
🌐
Medium
medium.com › @vdsnini › understanding-javascript-array-concatenation-and-string-conversion-bae9ed252d4a
Understanding JavaScript Array Concatenation and String Conversion | by Beenish Khan | Medium
June 24, 2024 - Conversion to Strings When the + operator is used between arrays, JavaScript first converts each array to its string representation. For arrays, the default string representation is a comma-separated list of their elements.
🌐
Mimo
mimo.org › glossary › javascript › array-concatenation
Mimo: The coding platform you need to learn Web Development, Python, and more.
Concatenation vs. join(): Use concatenation to merge arrays into a new array. Use join() when you need to convert an array into a single string.
🌐
Code.mu
code.mu › en › javascript › manual › array › join
The join method - concatenation of array elements into a string in JavaScript
The join method concatenates all array elements into a string with the specified separator in JavaScript.
🌐
DEV Community
dev.to › jrcharney › concatenation-of-strings-and-arrays-in-javascript-4i5a
Concatenation of Strings and Arrays in JavaScript - DEV Community
December 19, 2022 - Say you have an array variable, but you want each item to fill in a variable slot. The spread parameter will take the elements out of the array and treat them individually. We'll speak of this again later in this article. let str; const str0 = ""; const str1 = "Garnet"; const str2 = "Amethyst"; const str3 = "Pearl"; str = str0.concat(str1,str2,str3); // Returns: "GarnetAmethystPearl" // str: "GarnetAmethystPearl"
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.join()
Learn JavaScript Array join() By Practical Examples
November 7, 2024 - You'll learn how to use the JavaScript array join() method to concatenate all elements of an array into a string separated by a separator.
🌐
W3Schools
w3schools.com › jsref › jsref_concat_array.asp
JavaScript Array concat() 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 · JS by Category JS by Alphabet · JS Arrays · 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 ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-join-method
JavaScript Array join() Method | GeeksforGeeks
July 12, 2024 - The JavaScript Array join() Method is used to join the elements of an array into a string.
🌐
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
This tutorial shows you how to join a string array to a single string in JavaScript. ... JavaScript arrays support a native join method. The join method concatenates all array values using the given separator. The default separator is a comma ',': const tags = ['JavaScript', 'Node.js', 'Strings'] const result = tags.join() // 'JavaScript,Node.js,Strings' const result = tags.join(', ') // 'JavaScript, Node.js, Strings'