Working with Strings in JavaScript - How Can You Find the Position of a Substring in a String?

Tell us what’s happening:

Hello guys. First of all great thanks to the whole team for their great work. I have a little question, I think there is a little mistake in the explanation. It says the substring"awsome" starts at index 16 but when i count I see that it should be index rather index “14”. Can someone enlighten me on this question?
(I think there is another mistake in the video at timestamp 2:00 )Thanks in advance.
Here is the youtube URL of the video, (please look at timestamp 1:30) : https://www.youtube.com/watch?v=k2QaBPHl_00&t=92s

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Working with Strings in JavaScript - How Can You Find the Position of a Substring in a String?

1 Like

Well if its an index with in an array It starts on 0. :face_with_monocle:

1 Like

Thanks for your answer. I totally agree, I started caounting from 0 but I keep getting a different result than the one showed by the instructor :pensive:

The values shown in the video are wrong. It is 14 and 27, not 16 and 28

let sentence = "JavaScript is awesome!";
let position = sentence.indexOf("awesome!")
console.log(position) // 14
let sentence = "JavaScript is awesome, and JavaScript is powerful!";
let position = sentence.indexOf("JavaScript", 10);
console.log(position) // 27

I opened an issue for it.

1 Like