js to determine whether the array contains

You can use the indexOf() method of the array. If the return value is -1, it means it does not exist, and if the return value is an integer greater than -1, it means it exists. For example:
var arr = [1,2,3];
arr.indexOf(1); // return 0
arr.indexOf(5); // return -1
Attached: the return value is the first element in the array in the array s position

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326480604&siteId=291194637