+ 1
Why Zero?
var thor = "Thor: Ragnarok is fucking awesome!"; var summary = thor.lastIndexOf("Thor"); console.log(summary); - The answer should be 6. But on the Code Playground the answer is zero. Can someone explain me this?
2 Answers
+ 7
lastIndexOf returns the index at the beginning of the string that was searched for.
So in this case 'Thor' starts at index 0.
If you searched for 'Ragnarok' it would have returned 6
+ 3
the method lastIndexOf searches for string like "Thor" in your variable. So you just have used the word Thor one time so it will give out you the first index of the last word which equals "Thor"
another example: "Thor Thor".lastIndexOf("Thor"); //would be 5