I have a string that I need to split on a given index and then return both parts, seperated by a comma. For example:
string: 8211 = 8,211
98700 = 98,
You can easily expand it to split on multiple indexes, and to take an array or string
const splitOn = (slicable, ...indices) =>
[0, ...indices].map((n, i, m) => slicable.slice(n, m[i + 1]));
splitOn('foo', 1);
// ["f", "oo"]
splitOn([1, 2, 3, 4], 2);
// [[1, 2], [3, 4]]
splitOn('fooBAr', 1, 4);
// ["f", "ooB", "Ar"]
lodash issue tracker: https://github.com/lodash/lodash/issues/3014