Javascript Array sort_text(direction, index)

Description

Javascript Array sort_text(direction, index)


Array.prototype.sort_text = function(direction, index) {
    direction = direction === undefined ? 'asc' : direction;
    direction = direction === 'asc' ? 1 : -1;
    this.sort(function(a, b) {
        if (a[index] < b[index]) return -direction;
        if (a[index] > b[index]) return direction;
        return 0;
    })//from   w  w w.  j a  v a  2 s .c o m
};



PreviousNext

Related