Skip to content

The mapping that maps one value to more values.

Notifications You must be signed in to change notification settings

damianc/spreadMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

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]

About

The mapping that maps one value to more values.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published