From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Searching strings

Searching strings - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Searching strings

- [Instructor] There are a few built in utilities that are part of JavaScript that can help us complete common tasks like searching strings. Let's take a look at how a few of these might work. All right so we're going to create a variable here called planet, which will be set to earth. And then we'll use one of these methods called startsWith. So console log planet.startsWith Ear. We're going to make sure that planet, this variable starts with those letters, E-A-R. If that's true, it's going to return true. If false, it'll return false. So do note that this is case sensitive. So if you say lowercase E, you're going to see that it's false. We can also use endsWith to search a string. So we can use endsWith, and it looks like that's true. If I replace this with an S, it will be non-true. If you're ever in a situation where you want to search within a string, you can use .includes. So we can say planet.includes h.…

Contents