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

Array.prototype.join() β€” custom separator

πŸ“– Usage Example
const nums = [1, 2, 3]
nums.join(' - ')  // β†’ '1 - 2 - 3'
nums.join('')     // β†’ '123'

Pass any string as the separator to join() to control how elements are delimited.

Array.prototype.join() β€” any separator

join() accepts any string as the separator, including empty string, spaces, or multi-character strings.

Challenge: Implement joinWith(arr, sep) that joins the array using the given separator.

joinWith(['a', 'b', 'c'], '-') // β†’ 'a-b-c'
joinWith(['a', 'b', 'c'], '')  // β†’ 'abc'
πŸ’‘ Hints (2)
  • β€’ `join('')` concatenates all elements with no separator between them.
  • β€’ The separator only appears *between* elements, not before the first or after the last.