Arrays: using splice, slice, split, and join

Example output

The JavaScript code