Array to Array.prototype.toLocaleString()
It returns a string representation of this array object.
Example: The code creates an array arr containing name, number1, and number2, then converts it to a string using toLocaleString(), and prints the string.
Javascript
// User inputs. let name = [ "sahil" , "zain" , "deepanshu" ]; let number1 = 3.45; let number2 = [23, 34, 54]; let arr = [name, number1, number2]; // Applying array.toLocaleString function let string = arr.toLocaleString(); // Printing string. console.log(string); |
Output
sahil,zain,deepanshu,3.45,23,34,54
JavaScript Object toLocaleString() Method
The Object.prototype.toLocaleString() method returns a local specific string representation of this object using the locale of the environment. Derived objects like an array, number, date, typedarray, and BigInt can override this method.
Syntax:
object.toLocaleString()
Return Value: It returns a string representation of this object.
Objects overriding toLocaleString():
Contact Us