Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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]
```