javascript - Difference between string.indexOf() and string.lastIndexOf()? -


what's difference between string.indexof() , string.lastindexof() in javascript?

var temp = state.indexof("tmp");     var temp = state.lastindexof("tmp"); 

from mdn :

the indexof() method returns index within calling string object of first occurrence of specified value, lastindexof() method returns index within calling string object of last occurrence of specified value

so indexof return first occurrence of value , lastindexof return last occurence of value.

example (copied mdn):

var anystring = "brave new world"; var = anystring.indexof("w")); // result = 8 var b = anystring.lastindexof("w")); // result 10 

both of method return -1 if value not found

more :


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -