const cities = ['London', 'Paris', 'Tokyo']; const joinedCities = cities.join(); console.log(joinedCities); // London,Paris,Tokyo
var myStrings = ["hello", "world"];
<script> var arr=['j','a','v','a','T','p','o','i','n','t']; //array elements var str=arr.toString(); //toString() method implementation document.write("After converting into string: "+str); </script>
ToStringArray() is a method that converts the given array to an array of strings. When we want to convert the values into various lines, it can be use as a string template. The ToStringArray() method converts all the items in the given array into strings and returns them as an array. The first item in the returned collection will be “0”.The toString() method converts an object to a string. The Array() function does the same for arrays.
- To convert a specific property of an object to a string, for example,
- When you want to convert an entire list of things into rows and then concatenate them into one column.
let str: string = "0,1,2,3,4"; let arr: array = str.split(","); console.log(arr);