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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -