Saturday, January 14, 2012

Javascript(remove selected index of an array)


//remove the array selected index
        function removeA(arr) {
            var what, a = arguments, L = a.length, ax;
            while (L > 1 && arr.length) {
                what = a[--L];
                while ((ax = arr.indexOf(what)) != -1) {
                    arr.splice(ax, 1);
                }
            }
            return arr;
        }




//remove to take care of IE8 and below-
                if (!Array.prototype.indexOf) {
                    Array.prototype.indexOf = function (what, i) {
                        i = i || 0;
                        var L = this.length;
                        while (i < L) {
                            if (this[i] === what) return i;
                            ++i;
                        }
                        return -1;
                    }
                }

No comments:

Post a Comment