Posted at

jsでseparatorを要素として含めたsplit

More than 1 year has passed since last update.

> const splitKeep = (str, separator) => str.split(separator).reduce((p, c) => [...p, separator, c])

> splitKeep('a,b,c', ',')
[ 'a', ',', 'b', ',', 'c' ]