Home > Article > Web Front-end > JavaScript version of in_array function (determining whether a specific value exists in an array)_javascript skills
We often use this same logic to determine whether a string or number is in an array. Many programming languages have such specialized functions, such as PHP's in_array(). So does JS have such a function? Unfortunately, JS does not have such a function, so I thought about whether the great JQ encapsulated this function and found the API. JQ did encapsulate this function
jQuery.inArray( value, array ) Search Returns the specified value in an array and returns its index (or -1 if not found).
value The value to search for.
array is an array through which to search.
Of course, in the process of learning, I also wrote such a function myself: