Find the position of one string in another
How to solve it
To get the index of a substring in another string, we can use the
indexOf
method. 'wxyz'.indexOf('xy');
// output: 1
'together'.indexOf('ther');
// output: 4
Remember that strings in JavaScript are zero-indexed (see here). That means that we have to start counting with 0. So, the index of
is
in paris
is 3, although is
starts at the fourth character.