free source code :-
content of table is
indexOf( ) string method
lastIndexOf( ) string method
search( ) string method
Difference between indexOf and search
includes( )string method
startWith( )
endWith( )
indexOf( ) string method : - This javaScript string method get the position of given word's first occurrence.
Example of indexOf( ) :- If given text is "My name is soham";
and You are searching for "name" in the indexOf method. You will get 3 in result. Because in "name" , n is first character so the position of n is result position number of indexOf( ). method.
Note: IndexOf( ) search and count from left to right and return position of first occurrence only.
lastIndexOf( ) string method : - This JavaScript string method return the position of last occurrence but it count same as indexOf( ) method ( left to right ) and search from Right to left .
Example :- Given text is "This glass of water has no water."
search for "water" in given text you will get 25 position number for water. from Right side to left side lastIndexOf( ) start searching and from left side to right side it start counting.
Hence result is 25
What happens if searching text like name and water is not exist in given text ?
IndexOf and lastIndexOf method return -1 for no match.
Difference between indexOf( ) and search( )
IndexOf() method get no regular expression.
search() method has no second parameter to pass.
includes() : - return true for match occurrence and false for no match.
startWith() :- Return true if the text is start with searching text with is passed in startWith method else return false.
endWith( ) : - return true if the text is end with searching text with is passed in endWith() method else return false.
No comments:
Post a Comment