Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ** You should simply use indexOf or some ... that's are JS 1.6 Array methods **
- Array.prototype.has = function(obj) {
- return this.indexOf(obj) !== -1;
- };
- Array.prototype.has = function(obj) {
- return this.some(function(e){return e === obj});
- };
- ** This implementation is for multiple search (more than one value that should be present) **
- Array.prototype.has = function() {
- var i = arguments.length,
- result = [];
- while(i)
- result.push(this.indexOf(arguments[--i]) !== -1);
- return result.every(function(e){return e});
- };
- alert([1,2,3].has(3)); //true
- alert([1,2,3].has(2,4)); // false
- alert([1,2,3].has(1,2,3)); // true
Add Comment
Please, Sign In to add comment