You can use the function below for the same purpose, the second parameter can be an array or an object, and the first parameter is the value you are looking for in an array or object.
function inStruct(val,structure) { for(a in structure) { if(structure[a] == val) { return true; } } return false; } if(inStruct('Z',['A','B','Z'])) {
// this function passes through inherited properties as well
ie in some where are your included js libraries
Array.prototype.foo = 10;
than
instruct(10,[1,2,3]) // will return true
the same thing will happen for objects. check this fiddle http://jsfiddle.net/rQ8AH/17/
EDITED ::
Thanks to everyone for the comments ... this is an updated code, I thought it was better to keep the old function too. therefore, some may notice the difference.
function inStruct(val,structure) { for(a in structure) { if(structure[a] == val && structure.hasOwnProperty(a)) { return true; } } return false; }
source share