Skip to content

Instantly share code, notes, and snippets.

@jasonwaters
Last active December 23, 2015 12:09
Show Gist options
  • Save jasonwaters/6633660 to your computer and use it in GitHub Desktop.
Save jasonwaters/6633660 to your computer and use it in GitHub Desktop.
javascript contains method
<html>
<body>
<script type="text/javascript">
Object.prototype.contains = function(value) {
for(key in this) {
if(this.hasOwnProperty(key) && this[key] == value) {
return true;
}
}
return false;
}
console.log([1,2,3,4,5].contains(3));
console.log([1,2,3,4,5].contains(10));
console.log({'kitten': 1, 'dog': 12}.contains(12));
console.log({'kitten': 1, 'dog': 12}.contains(15));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment