Monday, May 21, 2018

javascript - jQuery: how to check if a specific element is already in an array





How can I check if the var element exists or not in the array sites?



var sites = array['test','about','try'];
var element = 'other';

Answer




You can use indexOf() method like following.



if(sites.indexOf(element) > -1) {
//exist
}

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...