乐趣区

Javascript数组过滤数组去重数组排序

数组大小排序:

function sortResult(value1,value2){return value1-value2;}

数组去重:

function uniq(array){var temp = [];
    var index = [];
    var len = array.length;
    for(var i = 0; i < len; i++) {for(var j = i + 1; j < len; j++){if (array[i] === array[j]){
                i++;
                j = i;
            }
        }
        temp.push(array[i]);
        index.push(i);
    }
    return temp;
}

已知数组:

var numbers=[1,2,3,4,5,4,3,2,1,100,2,34];

数组过滤:

var filterResult=numbers.filter(function(item,index,array){return (item>2);
});

结果输出:

console.log(uniq(filterResult).sort(sortResult));//[3, 4, 5, 34, 100]   
退出移动版