Home > Web Front-end > JS Tutorial > body text

Simple Tip: Parsing jQuery - Grep

WBOY
Release: 2023-08-28 17:01:09
Original
1266 people have browsed it

简单技巧:解析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;
	}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template