Categories
JavaScript Answers

How to reduce array to a single string with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *