jQuery
Utility Methods
Iterate, merge, and filter with jQuery helpers.
By EZ4Code Team
utilitieshelpers
Code
// Iterate over a collection
$("li").each(function (i) {
console.log(i, $(this).text());
});
// Map to a new array
const texts = $("li").map(function () {
return $(this).text();
}).get();
// Merge objects
const defaults = { limit: 10, page: 1 };
const opts = $.extend({}, defaults, { limit: 20 });
console.log(opts); // { limit: 20, page: 1 }
// Array helpers
$.grep([1, 2, 3], n => n > 1); // [2, 3]
$.inArray(2, [1, 2, 3]); // 1
$.isArray([]); // true
$.trim(" hi "); // "hi"Explanation
each() iterates over jQuery collections with this bound to each DOM element. $.extend merges objects (shallow by default), and $.map/grep provide functional array utilities. These helpers predate modern JS but remain useful for consistency in jQuery codebases.
More jQuery Snippets
Selectors
Select elements by id, class, attribute, and pseudo-filters.
Events & Delegation
Bind handlers with on(), support delegation and namespaced removal.
DOM Manipulation
Get/set text, html, attributes, classes, and insert nodes.
AJAX Requests
Use $.ajax, $.get, $.post, and load with promises.
Effects & Animation
Show, hide, fade, slide, and animate elements.
Traversing the DOM
Navigate relatives and filter the matched set.