Wednesday, April 25, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...