Home > Backend Development > PHP Tutorial > in_array() in javascript finds element value in array

in_array() in javascript finds element value in array

巴扎黑
Release: 2016-11-24 14:39:44
Original
1436 people have browsed it

in_array() has the same function as in_array() in php

Js code

//Find element value in array

function in_array(v, a) {  
  var i;  
  for (i = 0; i < a.length; i++) {  
    if (v === a[i]) {  
      return i;  
    }  
  }  
  return -1;  
} // 返回-1表示没找到,返回其他值表示找到的索
Copy after login


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