Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Mar 24, 2012

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
You can’t perform that action at this time.