Skip to content

Instantly share code, notes, and snippets.

@williammalo
Created March 23, 2012 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williammalo/2174082 to your computer and use it in GitHub Desktop.
Save williammalo/2174082 to your computer and use it in GitHub Desktop.
Determine if a value is in a array

This is a fork of a function by MathRobin. It's a bit longer, but it's made to work in older browsers that don't support indexOf.

function(a,b,c,d){for(c in b)d|=b[c]===a;return!!d}
var inArray = function(a,b,c,d){for(c in b)d|=b[c]===a;return!!d}
document.write(inArray("foo",["foo","bar","lorem","ipsum"]))​​​​​
//will write true on the page
@MathRobin
Copy link

Hey! Check the latest revision, with the update by jed and all the explanations needed ;)
https://gist.github.com/2171362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment