JS Built-ins
← Array206 / 226
ArrayArray.prototype.toStringbeginner

toString of Empty Array

πŸ“– Usage Example
const arr = []
arr.toString()  // β†’ ''  (empty string)

toString() on an empty array returns an empty string.

Array.prototype.toString β€” Empty Array

Calling toString on an empty array returns an empty string ''. This is consistent with [].join(',') also returning ''.

Implement emptyToString which returns the result of calling toString() on an empty number array.

πŸ’‘ Hints (2)
  • β€’ Create an empty array literal and call toString() on it
  • β€’ Use a type assertion ([] as number[]) to satisfy TypeScript