Wednesday, 25 April 2018

javascript - how to simplify this statement using indexOf?


The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.



In your case, instanceof wont help you. You can use indexOf() with array as follow.


var arr = [1, 2, 3];
// Check if a is present in the arr array
if (arr.indexOf(a) > -1) {
return "correct";
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...