Filter array by a function - Node.js Array

Node.js examples for Array:Array Operation

Description

Filter array by a function

Demo Code


Array.prototype.where = function( f ) {
    var res = [];
    for ( var i = 0, n = this.length; i < n; i++ ) {
        if ( f( this[ i ] ) ) res.push( this[ i ] );
    }/*  ww w.  j  a v  a2 s  .c  o m*/
    return res;
}

Related Tutorials