I have this array [ "one", "two", "three" ].
Now, given an index n, how can I find the index of the array element, in which the character at index n is located? By character at index n I mean the character of all the strings overall, i.e. of "onetwothree". For example: the character at index n = 2 is "e", for n = 3, it’s "t", for n = 4 it’s "w", etc.
The result I’m looking for is the index of the array element where the character at index n was originally found.
Examples for the given array:
| Input | Output | … because the character at index n was |
|---|---|---|
n = 2 |
0 |
"e" from "one" |
n = 3 |
1 |
"t" from "two" |
n = 4 |
1 |
"w" from "two" |
n = 9 |
2 |
"e" from "three" |
charAt?