Home > CMS Tutorial > WordPress > Quick tip: A closer look at jQuery - Grep

Quick tip: A closer look at jQuery - Grep

王林
Release: 2023-08-28 17:49:10
Original
1341 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 Quick tip: A closer look at 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