Object.prototype.toLocaleString

Returns a string representation of an object.

Syntax

toLocaleString(locale?)

Parameters

Return value

A string representation of the object.

Examples

{}.toLocaleString()
"[object Object]"
let vehicle = {
  speed: 10,
  unit: "km/h",
  toString() {
    return `${this.speed} ${this.unit}`
  },
  toLocaleString(locale) {
    if (locale == "en-US")
        return `${(this.speed / 1.609344).toFixed(1)} mph`
    else
        return this.toString()
  }
}
vehicle.toLocaleString("en-US")
"6.2 mph"