ABOUT CONTACT
Prev Page Next Page
Top

JavaScript String Search

➢String indexOf()
➢String lastIndexOf()
➢String startsWith()
➢String endsWith()

JavaScript String indexOf()

➢The indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string:

EXAMPLE:

let Name = "Susindra Reddy";
Name.indexOfName("Reddy");

JavaScript String lastIndexOf()

➢The lastIndexOf() method returns the index of the last occurrence of a specified text in a string:

EXAMPLE:

let Name = "Susindra Reddy";
Name.lastindexOfName("Reddy");

JavaScript String search()

➢The search() method searches a string for a specified value and returns the position of the match:

EXAMPLE:

let Name = "Susindra Reddy";
Name.search("Reddy");

JavaScript String match()

➢The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.

EXAMPLE:

let Name = "Susindra Reddy";
Name.match(/ddy/r);

JavaScript String includes()

➢The includes() method returns true if a string contains a specified value.

EXAMPLE:

let Name = "Susindra";
Name.includes("Reddy");


JavaScript String startsWith()

➢The startsWith() method returns true if a string begins with a specified value, otherwise false:

EXAMPLE:

let Name = "Susindra";
Name.startsWith("B");

JavaScript String endsWith()

➢The endsWith() method returns true if a string ends with a specified value, otherwise false:

EXAMPLE:

let Name = "Susindra";
Name.endsWith("Reddy");

EXAMPLE:

let Name = "Susindra";
Name.endsWith("Reddy", 9);

Prev Page Next Page





FEEDBACK

Rating


Message