Answer the question
In order to leave comments, you need to log in
How to explain the operation of the indexOf( ) method in this case?
Hello ! Trite, but incomprehensible!
console.log('Widget with id and'.indexOf('Widget')); // 0 ok
console.log('Widget with id and'.indexOf('with')); // 7 ok
console.log('Widget with id and'.indexOf('id')); // 1 wtf?
console.log('Widget with id and'.indexOf('and')); // 15 ok
console.log('Widget with id and'.indexOf('Widget')); // 0 ok
console.log('Widget with id and'.indexOf('with')); // 7 ok
console.log('Widget with ids and'.indexOf('ids')); // 12 ok
console.log('Widget with id and'.indexOf('and')); // 15 ???
id
turned out to be 1??? because it is in the 12th position. . . And why in the second block of code ids
on the normal ( 12th position ) BUT for some reason and
did not move one position, but remained on the 15th, because we added one character id
s ? I don't understand!
Answer the question
In order to leave comments, you need to log in
Widget contains the id substring. What is not clear?
What about and. So you added the symbol in the wrong place.
I recommend to sleep))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question