剔除数组中的NaN

var arr = [NaN,1,21,32,NaN,41,5];
Array.prototype.delNaN = function () {
    var arr = [];
    for (var i = 0; i < this.length; i++) {
        if (this[i] === this[i]) {
            arr.push(this[i]);
        }
    }
    return arr;
};
console.log(arr.delNaN())

你可能感兴趣的:(剔除数组中的NaN)