While working with javascript arrays, there is often a requirement to convert an array to a string without commas. This article demonstrates how to convert an array to a string without commas as separators in javascript.
Convert array to string without comma using join()
Javascript’s join(separator)Â method will join all the elements of an array into a single string divided by the separator passed in the method’s argument.
Example1:-
Convert the array [“Javascript”, “Is”, “Popular”,”Language”] to string without commas
Code:-
let stringArray = ["Javascript", "Is", "Popular","Language"]; let finalString = stringArray.join(""); console.log(finalString);
Output:-
JavascriptIsPopularLanguage
Explanation:-
Frequently Asked:
- The join() method is used.
- Blank value(“”) is passed in as an argument while converting the array to a string value.
- This string value is stored in finalString and printed on the console.
Example2:-
Convert the array [“Javascript”, “Is”, “Popular”,”Language”] to string without commas separated by dash.
Code:-
let stringArray = ["Javascript", "Is", "Popular","Language"]; let finalString = stringArray.join("-"); console.log(finalString);
Output:-
Javascript-Is-Popular-Language
Explanation:-
- The join() method is used.
- Dash(“-“) is passed in as an argument that becomes a separator while converting the array to a string value.
- This string value is stored in finalString and printed on the console.
Read More:
I hope this article helped you with conversions of the array to a string without commas in javascript. Good Luck !!!
This is great , I was struggling with this issue. Thanks for the help . ?