The Javascript string has an indexOf method that can return the position of a character in the specified string. This article describes how to add a similar method to the Javascript array.
<Script type = "text/javascript"> // <! [CDATA [[]. indexOf | (Array. prototype. indexOf = function (v) {for (var I = this. length; I -- & this [I]! = V;); return I;}); var B = [0, 1, 'hahaha', 3, 4, 'haobao', 6, 7, 8, 9]; document. write ("<br> B =", B. join (","), "<br>"); document. write ("<br> B. indexOf (2) = ", B. indexOf (2); document. write ("<br> B. indexOf ('hire') = ", B. indexOf (' '); //]> script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Run the above Code.
If you want to see how to use javascript indexOf, please refer to the following article
Javascript indexOf function instructions
JavaScript indexOf case-insensitive javascript skills