javascript - how to simplify this statement using indexOf? -
this question has answer here:
how can simplfy following text inside if statement in javascript using "indexof"?
if (a === 1 || === 2 || === 3) { return "correct"; };
i guessing array needs made 1,2, , 3, unsure of how instanceof after that
*edited indexof instead of instanceof
the
instanceof
operator tests whether object has in prototype chain prototype property of constructor.
in case, instanceof
wont you. can use indexof()
array follow.
var arr = [1, 2, 3]; // check if present in arr array if (arr.indexof(a) > -1) { return "correct"; }
Comments
Post a Comment