JS Built-ins
← Array225 / 226
ArrayArray.prototype.toLocaleStringintermediate

Mixed Array toLocaleString

πŸ“– Usage Example
const mixed = [1, 'hello', new Date('2024-01-01')]
mixed.toLocaleString('en-US')
// each element is formatted individually

toLocaleString() calls toLocaleString() on each element individually, useful for mixed-type arrays.

Array.prototype.toLocaleString β€” Mixed Types

toLocaleString() works on arrays containing mixed types. Each element's own toLocaleString() is called.

Implement mixedToLocale(arr) that returns arr.toLocaleString() for an array of numbers and strings.

πŸ’‘ Hints (2)
  • β€’ Strings use their own `toLocaleString()`, which just returns the string itself.
  • β€’ Numbers use `Number.prototype.toLocaleString()` for locale-sensitive formatting.