Home > Web Front-end > JS Tutorial > Write js extension method to determine whether an array contains an element_javascript skills

Write js extension method to determine whether an array contains an element_javascript skills

WBOY
Release: 2016-05-16 17:16:38
Original
1330 people have browsed it

In C# syntax, you can use the Contains method to determine whether a collection contains an element, but how to deal with similar problems in JavaScript? There is no Contains method in js.
We can use the prototype extension of js to encapsulate our own Contains method.

js code:

Copy code The code is as follows:



Verification found that array objects using the contains method do not need to be explicitly declared, that is, the italicized part in the above code can be abbreviated as:
Copy code The code is as follows:

var $subCategoryID = $("#hidSubCategory").val().split(" ,");
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template