I have heard that JavaScript has a function called search()
that can search for a string ( lets call it A ) in another string ( B ) and it will return the first position at which A was found in B.
var str = "Ana has apples!";
var n = str.search(" ");
The code should return 3 as its the first position in which the space was found in str
.
And I was wondering if there is a function that can find the next spaces in my string.
For example I want to find the length of the first word in my string and I could easily do this If I knew the its starting position and its ending one.
If there is such a function, are there any better than it for such things?