Home > php教程 > PHP开发 > body text

Use js to determine whether an array contains an element (similar to in_array() in php)

高洛峰
Release: 2016-12-22 13:39:13
Original
1738 people have browsed it

while case is the fastest

function contains(arr, str) {
    var i = arr.length;
    while (i--) {
           if (arr[i] === str) {
           return true;
           }   
    }   
    return false;
}
Copy after login


For more information on using js to determine whether an array contains a certain element (similar to in_array() in php), please pay attention to the PHP Chinese website for related articles!


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!