📋 Table Of Content
Array to String using toString() method
const array = ['one','two','three'] console.log(array.toString()) //Output: "one,two,three"
This method converts the array and return the string with commas as the separator between the elements.
You can also convert mix array to string. Here is an example with an mix array.
const array = ['one','two','three', 4, 5, 6] console.log(array.toString()) //output : "one,two,three,4,5,6"
toString() method convert each element of different data-type into a string.
If you don't want to convert the array to string with the comma separator then you can use the
Just pass the required separator as a parameter in
const array = ['one','two','three'] console.log(array.join('+')) //output : "one+two+three" console.log(array.join('/')) //output : "one/two/three" console.log(array.join(' ')) //output : "one two three"
Now, if you pass an empty string as a separator then it will return a string without any comma separator.
const array = ['one','two','three'] console.log(array.join('')) //output: onetwothree
- Line continuation | Long statement in Multiple lines in Python
- Find Length of Dictionary in Python with Examples
- Reverse an Array in Python (Using Numpy And Array Module)
- Python import from parent directory
- How to use Pi in Python? (math and numpy module)
- FileNotFoundError: No such file or directory Error Python