Well, when I execute code in javascript and I have a string like for example:
var variable="esto es una . cadena con punto".search(".");
Well, it gives 0, I have searched and apparently search() returns 0 when it does not have parameters or they are not initialized, something that I do not understand because I am explicitly passing the string that it has to search for...
This is because the search method does not receive a string, but a regular expression or a string to make a regular expression, i.e. your code is equivalent to
the
.
in a regular expression means any character, so you can correct your code by escaping the dot so it doesn't take it as any character:I have found a different way to find the index or position of the "." character, you can use:
It will return your position.