Daniel Daniel - 2 years ago 107
Javascript Question

jQuery: How can I check if a value exists 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 Source

You can use indexOf() method like following.

if(sites.indexOf(element) > -1) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download