jQuery.map(arrayOrObject, callback) (alias $.map) translates every item in an array, array-like object, or plain object into a new array of results (arrays since 1.0; plain objects since 1.6).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.map(array, function (value, index) { … }) → Array
$.map(object, function (value, key) { … }) → Array
$.map([0, 1, 2], function (n) { return n + 4; })
→ [4, 5, 6]
// return null / undefined → skip item
// return [a, b] → flatten one level
Call
What it does
array / object
Source to translate
callback
Maps each item → result value(s)
Return
New Array
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Start with an array, array-like object, or plain object.
Step 2
Write a callback: arrays get (value, index); objects get (value, key).
Step 3
Return a value to keep it, null/undefined to skip, or an array to flatten one level.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Transform Each Value
Add 4 to every number in an array.
jQuery
var result = $.map([0, 1, 2], function (n) {
return n + 4;
});
console.log(result); // [4, 5, 6]
Branch. Positive values return n + 1; zero returns null.
Skip.null / undefined are omitted from the result.
Keep.1 → 2 and 2 → 3 remain.
Frequently Asked Questions
jQuery.map(collection, callback) walks every item in an array, array-like object, or plain object and builds a new array from the values your callback returns. It is a transform utility — not tied to DOM selections.
jQuery.each() runs side effects and returns the original collection. jQuery.map() collects callback return values into a brand-new array. Also note the callback argument order differs: $.map uses (value, index) for arrays, while $.each uses (index, value).
jQuery.map(array, fn) is a static utility for any data. $(selector).map(fn) is an instance method that maps over elements inside a jQuery DOM collection. Official docs: to process a jQuery object, use .map() instead.
Any value to include in the result array; null or undefined to skip the item; or an array of values, which jQuery flattens one level into the final result.
No. It always returns a new array. Your callback could mutate nested objects if you choose, but the top-level collection reference stays the same.
Use jQuery.map() when you need to map plain objects, array-like objects, or when you want null/undefined filtering and one-level flattening built in. Array.map() only works on arrays and does not flatten nested arrays from the callback.