Home >Web Front-end >JS Tutorial >Simple Tip: Parsing jQuery - Grep
In the latest episode of "Anatomy of jQuery," we'll lift the lid on $.grep and see exactly what's going on behind the scenes.
Subscribe to our YouTube page to watch all video tutorials!
grep
jQuery source// jQuery source for the grep method 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; }
Hopefully you now have a better understanding of what's going on behind the scenes. Remember: any time you need to remove items from an array, $.grep will do the job just fine!
The above is the detailed content of Simple Tip: Parsing jQuery - Grep. For more information, please follow other related articles on the PHP Chinese website!