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

Format Amounts as Currency

πŸ“– Usage Example
const prices = [9.99, 24.50]
prices.toLocaleString('en-US', {style:'currency', currency:'USD'})
// β†’ '$9.99,$24.50'

Pass locale and options to toLocaleString() to format numeric values as currency.

Array.prototype.toLocaleString β€” Currency Formatting

Combine Array.prototype.map with Number.prototype.toLocaleString to format each amount as a USD currency string, then join them.

Implement formatCurrencies(amounts) that maps each number to n.toLocaleString('en-US', {style:'currency', currency:'USD'}) and joins with ', '.

πŸ’‘ Hints (2)
  • β€’ Use `.map()` to convert each number, then `.join()` to combine results.
  • β€’ Pass `{ style: "currency", currency: "USD" }` as the second argument to `toLocaleString`.