I have a String like `Lion is the king` I need to split it in such a way that it returns an array **like this** :

```
L
Li
Lio
Lion
""
i
is
""
t
th
the
""
k
ki
kin
king

```

**My CODE** :

```
List<String> splitList = name.split(' ');
List<String> indexList = [];
for (int i = 0; i < splitList.length; i++,) {
  for (int j = 0; j < splitList[i].length; j++) {
    indexList.add(splitList[i].substring(0, j).toLowerCase());
  }
}
return indexList;

```

Here `name` is a *String*.

**Result of the above code**:

```
L
Li
Lio
""
i
""
t
th
""
k
ki
kin

```

**Problem with my code** :

In my code the last alphabet of every word is missing.

**Uses of this**:

I am using this for *searching* purposes, in short I am saving this `array` in `Firestore` and create a searching function using `array contains:` in `StreamBuilder`