Search a String Variable with JavaScript Methods

Offered By
Coursera Project Network
In this Guided Project, you will:

Write the JavaScript code to search through a string.

Compare JavaScript methods for searching through strings.

Use a JavaScript method to replace a value in a string.

Clock2 hours
IntermediateIntermediate
CloudNo download needed
VideoSplit-screen video
Comment DotsEnglish
LaptopDesktop only

In this intermediate-level project you will write JavaScript code to search through a string variable. You’ll use a variety of JavaScript methods to locate values within a string to determine whether they exist, find their position in the string, or even replace them with other values. The Notepad++ editor and Chrome browser are used to write inline JavaScript code and view the results. Note: This course works best for learners who are based in the North America region. We’re currently working on providing the same experience in other regions.

Skills you will develop

JavaScript replace()Javascript MethodsJavaScript search()StringsJava Syntax

Learn step-by-step

In a video that plays in a split-screen with your work area, your instructor will walk you through these steps:

  1. Declare a JavaScript variable and assign to it a string value, while demonstrating string-handling techniques.

  2. Use the JavaScript includes() method to search through a string to determine whether it contains a string of characters.

  3. Search through a string using the JavaScript search() method with the goal of returning the position of the matching characters or set of characters.

  4. Search through a string with the JavaScript indexOf() method to return the first occurrence of a specific value.

  5. Search through a string with the JavaScript lastIndexOf() method to return the last occurrence of a specific value.

  6. Locate and replace a value in a JavaScript string using the replace() method.

How Guided Projects work

Your workspace is a cloud desktop right in your browser, no download required

In a split-screen video, your instructor guides you step-by-step

Frequently asked questions

Frequently Asked Questions

More questions? Visit the Learner Help Center.