QUESTION IMAGE
Question
use indexof() and substr() or substring() to display the end of the sentence starting from the wordsqueaky.
note: your code will be tested with more values for oldsaying.
1 let oldsaying = \the squeaky wheel gets the grease.\;
2
3 / your solution goes here /
4
Step1: Find the index of "squeaky"
Use indexOf() method to find the starting index of the word "squeaky" in the oldSaying string.
let index = oldSaying.indexOf("squeaky");
Step2: Extract the substring
Use substr() (or substring()) method to extract the substring starting from the found index.
let result = oldSaying.substr(index);
// or let result = oldSaying.substring(index);
console.log(result);Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
let oldSaying = "The squeaky wheel gets the grease.";
let index = oldSaying.indexOf("squeaky");
let result = oldSaying.substr(index);
// or let result = oldSaying.substring(index);
console.log(result);