Função escrita utilizando apenas Javascript para verificar se um valor existe no Array.
Adicione a seguinte função em seu script.js
var contains = function(needle) { var findNaN = needle !== needle; var indexOf; if(!findNaN && typeof Array.prototype.indexOf === 'function') { indexOf = Array.prototype.indexOf; } else { indexOf = function(needle) { var i = -1, index = -1; for(i = 0; i < this.length; i++) { var item = this[i]; if((findNaN && item !== item) || item === needle) { index = i; break; } } return index; }; } return indexOf.call(this, needle) > -1; };
Exemplo de utilização:
var myArray = [0,1,2], needle = 1, index = contains.call(myArray, needle); // true
contains.call(myArray, needle); irá retornar “true”
Utilizando jQuery
Com jQuery você poderá utilizar a função inArray.
$.inArray(value, array)