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).
Remember
$.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
Pass a collection and a callback that returns the mapped value.
Start with an array, array-like object, or plain object.
Write a callback: arrays get (value, index); objects get (value, key).
Return a value to keep it, null/undefined to skip, or an array to flatten one level.
Use the new array result — the original collection is not replaced.
Piece
Required?
Role
array / object
Yes
Source to translate
callback
Yes
Maps each item → result value(s)
Return
—
New Array
Pseudocode
Pseudocode
function map(collection, callback):
result = []
for each (value, indexOrKey) in collection:
mapped = callback(value, indexOrKey)
if mapped is null or undefined:
continue // skip
if mapped is an array:
append each item to result // flatten 1 level
else:
append mapped to result
return result
// Callback this → window (global), not the item
Reference
Cheat Sheet
Keep these facts handy while transforming collections.
Topic
Detail
Syntax
jQuery.map(collection, callback)
Arrays
Since jQuery 1.0
Objects
Since jQuery 1.6
Callback (array)
(value, index)
Callback (object)
(value, key)
Skip item
Return null / undefined
Flatten
Return an array → one level
Try it
Live Preview
Run official-style $.map transforms on small sample data.
Browser demo of $.map() — same idea as the examples below.
Result
$.map([0, 1, 2], n => n + 4)
→ [4, 5, 6]
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
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]
Object source. Properties are walked as (value, key).
Transform. Each value is doubled.
Array out. Result is always an array of mapped values — not an object.
Keys tip. Return key instead of value if you need property names.
Edge Cases & Pitfalls
Check these before mixing $.map with $.each or DOM mapping.
order
Callback args: value first
$.map uses (value, index). $.each uses (index, value). Swapping them is a common bug.
dom
jQuery collections → use .map()
Official guidance: map DOM selections with $(sel).map(), not the static utility.
this
this is the global object
Inside the callback, this is window, not the current item. Use the value argument instead.
flatten
Returned arrays flatten one level only
Deeper nesting stays nested. Plan for a single flatten level when returning arrays from the callback.
Compatibility
Browser Support
jQuery.map() needs jQuery in the browser. Arrays/array-likes since jQuery 1.0+; plain objects since jQuery 1.6+. Works in all browsers supported by your jQuery build.
✓ jQuery 1.0+ · Objects 1.6+
jQuery.map()
Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded. Transform arrays, array-likes, and (since 1.6) plain objects.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.map()Browsers
Bottom line: Use $.map(collection, callback) to build a new array from data — use .map() for DOM collections.
Analysis
Performance Notes
Approach
Cost
Best for
$.map(arr, fn)
O(n)
Transform + optional skip/flatten
$.each(arr, fn)
O(n)
Side effects, no new array
arr.map(fn)
O(n)
Native arrays only
Prefer $.map when you need the new array (and null-skip / flatten). Prefer $.each when you only need to loop.
Remember
Key Takeaways
Role:$.map builds a new array from callback returns.
Args:(value, index|key) — value first.
Extras:null skips; arrays flatten one level.
DOM: use $(sel).map() for element collections.
One line:$.map(collection, fn) translates data into a new array — skip with null, flatten returned arrays, and remember value comes first.
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.