Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite+ 9
How do you count the index of a string in JavaScript?
For instance, the code below outputs 8 but I really don't understand why it gives 8 as the output var str = "This is SoloLearn"; var pos = str.indexOf("Solo"); alert(pos++);
4 Réponses
+ 14
Mofey
Solo start position at 8.
8th position is S.
javascript start count 0.
+ 18
It gives 8 as the output since the index of any string starts with 0.
The index of "Solo" is 8 so the pos variable will store 8 and display it and after that it will increment the pos value since
pos++ is a post increment operation , firstly the value will be assigned then it will be incremented
+ 10
Welcome Mofey ☺
+ 2
Oh, thank you so much <rabby> </ahad> At least I can say I've learnt something new today