Short code for checking if a variable also exists inside an array is needed.
Im thinking something like this:
var category='cars';
if (in_array(category, some_array)){
do stuff!
}
Is there any such function in js?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no native “in_array”-function in JavaScript (as in PHP), check out this solution:
http://phpjs.org/functions/in_array:432
Also a search would have lead you here:
JavaScript equivalent of PHP's in_array()