JS Built-ins
← Array112 / 226
ArrayArray.prototype.joinbeginner

Array.prototype.join() β€” join with comma-space

πŸ“– Usage Example
const words = ['Hello', 'World']
words.join(' ')  // β†’ 'Hello World'

Use join() to concatenate all array elements into a single string with a separator.

Array.prototype.join()

Array.prototype.join(separator?) joins all elements of an array into a single string, separated by the given separator. The default separator is a comma (,).

Challenge: Implement joinWithComma(arr) that joins the array with ', ' (comma followed by space).

joinWithComma(['a', 'b', 'c']) // β†’ 'a, b, c'
joinWithComma(['one'])         // β†’ 'one'
πŸ’‘ Hints (2)
  • β€’ `join(', ')` uses comma+space as the separator between elements.
  • β€’ An empty array joined returns an empty string `""`.