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"
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"
Comments
Post a Comment