PDA

View Full Version : grep alternative in javascript



sreek
01-05-2013, 11:19 AM
Hi

I used grep function of jquery but based on my project requirement i use only javascript so is any alternative of grep in javascript which function i have to use

plz help me


Thanks

bernie1227
01-06-2013, 01:55 AM
jquery source for grep:


function( elems, callback, inv ) {
var ret = [];
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ ) {
if ( !inv !== !callback( elems[ i ], i ) ) {
ret.push( elems[ i ] );
}
}
return ret;
}

Out of curiosity, why can't you use jquery? It's written in javascript.