Skip to content
Justice Tech School

Searching Strings

indexOf and lastIndexOf find a position, includes tests presence, startsWith and endsWith check the edges and search accepts a regular expression.

Example
const s = "learn javascript fast";
console.log(s.indexOf("java"), s.includes("fast"), s.startsWith("learn"), s.endsWith("x"));
console.log(s.search(/script/));

Exercise

Test for a part.

s.("fast")

Quiz Test

What does indexOf return when not found?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.