How to add an indexOf method to Javascript Array _ javascript skills

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.