javascript – Build list of prefixes, including the whole string

There is a string “abcdebfkj”, we need to transform this string to the below array:

expected o/p:  

("a", "a.b", "a.b.c", "a.b.c.d", "a.b.c.d.e", "a.b.c.d.e.b", "a.b.c.d.e.b.f", "a.b.c.d.e.b.f.k", "a.b.c.d.e.b.f.k.j")

I am able to do that, but was looking for more promising solution if any. I did that in O(n) time complexity. Please let me know if the below can be improved in any way.

function splitString(str) {
  const result = ();
  for (let i = 0; i < str.length; i++) {
  i === 0 ? result.push(str(i)) : result.push(`${result(i-1)}.${str(i)}`);
  return result;


How can I avoid checking the index and make the for loop work?