What I want is something like Array.join(separator), but which takes a second argument Array.join(separator, beforeLastElement), so when I say [f
Array.join(separator)
Array.join(separator, beforeLastElement)
[f
In-line solution using reduce:
[1, 2, 3, 4, 5].reduce((text, value, i, array) => text + (i < array.length - 1 ? ', ' : ' or ') + value); => 1, 2, 3, 4 or 5"