Sometimes, we want to reduce array to a single string with JavaScript.
In this article, we’ll look at how to reduce array to a single string with JavaScript.
How to reduce array to a single string with JavaScript?
To reduce array to a single string with JavaScript, we use the array join
method.
For instance, we write
const authors = ["some author", "another author", "last author"];
const authorString = authors.join(",");
console.log(authorString);
to call authors.join
with ','
to return a string with the strings in authors
joined into a new string with ,
separating the strings.
Conclusion
To reduce array to a single string with JavaScript, we use the array join
method.