Object.map
Object.map
Function
Iterate over the object and write the callback return value to the new object.
Syntax
object.map(callback)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(value, key, current). |
Return value
| Type | Description |
|---|---|
| Object | Returns the new object after mapping. |
Return object fields
The returned object uses the field names of the original object, and each field value is the callback return value. When the callback does not return a natural value, the field value is empty.
Example
prices = {a: 1, b: 2} result = prices.map(fn(value) { value * 10 }) // Output: {"a":10,"b":20} print result
Notes
- The returned object retains the original key name.
- The original object will not be modified.