Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damianc/spreadmap
The mapping that maps one value to more values.
https://github.com/damianc/spreadmap
Last synced: about 1 month ago
JSON representation
The mapping that maps one value to more values.
- Host: GitHub
- URL: https://github.com/damianc/spreadmap
- Owner: damianc
- Created: 2023-10-16T22:25:45.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-03T19:28:50.000Z (10 months ago)
- Last Synced: 2024-03-03T20:33:09.933Z (10 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spreadMap
It works like the `map()` method, but one value is mapped to more values. It is achieved by returning an array of values to spread into the final array from a callback passed to the method.
```
spreadMap(
(item, index, array) => array
)
```> As of **ES10** you can use built-in `flatMap()` method instead.
## Example
```
const arr = [1,2,3,4];
const sm = arr.spreadMap(
x => [x, x**2]
);console.log(sm);
// [1,1,2,4,3,9,4,16]
```