Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}

Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
}
据说while减迭代是js里最快的一种方法,不知道是不是真的,出自
http://stackoverflow.com/questions/237104/javascript-array-containsobj
posted on 2009-08-26 11:15  袁晓平  阅读(3141)  评论(0)    收藏  举报