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

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -