Home > Article > Backend Development > in_array() in javascript finds element value in array
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表示没找到,返回其他值表示找到的索