English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
indexOf()Returns the position of the first occurrence of the specified value in the string.
If the value is not found, it will return-1.
If the value exists multiple times, it will return the position of the first occurrence.
If you want to start searching from the beginning, uselastIndexOf()method.
Attention :For more information on Array methods, seeArray.indexOf().
string.indexOf(searchValue, start)
var str = 'Introduction de produits chimiques dans l'atmosphère'; str.indexOf('Pollution');// 4Testez et voyez‹/›
Attention :Cette méthode distingue les majuscules et les minuscules.
Tous les navigateurs supportent complètement la méthode indexOf() :
Méthode | |||||
indexOf() | Est | Est | Est | Est | Est |
Paramètres | Description |
---|---|
searchValue | (obligatoire) Représente la chaîne de caractères à rechercher |
start | (optionnel) Entier, représentant l'index de départ de la recherche ; par défaut 0 |
Valeur de retour : | la première apparitionsearchValuede l'index, s'il n'est pas trouvé, alors-1 |
---|---|
Version JavaScript : | ECMAScript 1 |
Retournez la position du caractère 'L' dans la chaîne, à partir de la position6Commencez la recherche :
var str = 'HELLO WORLD HELLO'; str.indexOf('L', 6);Testez et voyez‹/›