Javascript Array filterEmpty()

Description

Javascript Array filterEmpty()

Array.prototype.filterEmpty = function ()
{
    var arr = this;
    var i = arr.length;
    while (i--)//from  w  w w.j av a  2 s . c  om
    {
        if (arr[i] instanceof Array)
        {
            arr[i] = arr[i].filterEmpty();
            if (arr[i].length == 0)
            {
                arr.splice(i, 1);
            }
        }
        else
        if (arr[i] !== 0 && arr[i] == null)
        {
            arr.splice(i, 1);
        }
    }
    return arr;
};



PreviousNext

Related