Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:16:381316browse

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(" ,");
Statement:
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