/ Published in: JavaScript
URL: http://snook.ca/archives/javascript/testing_for_a_v
Simulates PHP in_array function.
['foo','bar'].has('foo') // returns true ['foo','bar'].has('foo',1) // returns 0
Expand |
Embed | Plain Text
Array.prototype.has=function(v,i){ for (var j=0;j<this.length;j++){ if (this[j]==v) return (!i ? true : j); } return false; }
Comments
Subscribe to comments
You need to login to post a comment.

Array.prototype.has = function(e, i) { return i || !!~this.indexOf(e); }