Skip to main content

Posts

Showing posts from January, 2020

How to convert an array into string using JavaScript?

An array to string using JavaScript: var Cities = ['Kolkata', 'Udaipur','Delhi','Mumbai','Chennai','Hyderabad','Bangalore'] // array Using toString() method var newArrCities = Cities.toString();  Output:  " Kolkata,Udaipur,Delhi,Mumbai,Chennai,Hyderabad,Bangalore " // , is the separator here Using join() method //It allows you to specify the separator or by default it will comma/(,) var newArrCities2 = Cities.join();  OR var newArrCities2 = Cities.join(",");  Output:  " Kolkata,Udaipur,Delhi,Mumbai,Chennai,Hyderabad,Bangalore " var newArrCities = Cities.join('*');  Output:  " Kolkata*Udaipur*Delhi*Mumbai*Chennai*Hyderabad*Bangalore "