In this article, you will learn about the Javascript Array built-in method Array.prototype.toString()
. How does this method work in javascript?
The Array.prototype.toString()
method is used to return a string containing all the elements of a specified array. This method separates them by a comma.
array.toString();
This method does not take any parameters. And the toString()
method does not change the original array.
Here are some examples of Array.prototype.toString()
method:
const language = ["Java", "C#", "Go", "JavaScript", "Python"];
console.log(language.toString());
// Output => "Java,C#,Go,JavaScript,Python"
const prices = ['₹7', 500, 8123, 12];
console.log(prices.toString());
//Output => "₹7,₹500.00,₹8,123.00,₹12.00"
//Using toString() on sparse arrays
console.log([1, , 3].toString());
//Output => '1,,3'
I hope this article will help you to understand the javascript Array built-in method Array.prototype.toString().
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments