Misc Map
# jQuery.map() Method
[jQuery Misc Methods](#)
## Example
Use $.map() to modify the values of an array
$(function(){var arr = ["a", "b", "c", "d", "e"]; $("div").text(arr.join(", ")); arr = $.map(arr, function(n, i){return(n.toUpperCase() + i); }); $("p").text(arr.join(", ")); arr = $.map(arr, function(a){return a + a; }); $("span").text(arr.join(", ")); })
[Try it Β»](#)
* * *
## Definition and Usage
The $.map() function is used to process each element in an array (or each property in an object) using a specified function, and returns the processed results encapsulated in a new array.
**Note:** 1. Before jQuery 1.6, this function only supported iterating over arrays; from version 1.6 onwards, it also supports iterating over objects.
2. The map() function also passes two arguments to the callback function: the first is the current element or property value being iterated, and the second is the array index or object property name of the current item.
3. The return value of the function will be an element in the result array. If the return value is null or undefined, it will not be added to the result array.
* * *
## Syntax
_$_.map( object, callback )
| Parameter | Description |
| :--- | :--- |
| _object_ | Array/Object type. The specified array or object to be processed. |
| _callback_ | Function type. The specified processing function. |
* * *

## More Examples
(#)
Maps each value in the original array to a new array after adding 4.
(#)
Maps values greater than 0 in the original array to a new array after adding 1.
(#)
Maps each value in the original array and the result of adding 1 to that value to a newly generated array.
(#)
Maps each value in the original object to a newly generated array after multiplying by 2.
(#)
Maps the keys in the object to a newly generated array.
(#)
Maps the square of each value in the original array as the return result to a newly generated array.
(#)
Removes an element by returning null in the processing function. Removes values less than 50, and reduces the value of elements not removed by 45.
(#)
Adds elements to the final result array by returning an array in the processing function.
* * jQuery Misc Methods](#)
YouTip