Home > @josh-brown/vector > Vector > map
Constructs a vector by transforming the values of another vector.
Signature:
map(valueFromEntry: (entry: S, index: number) => S): Vector<S>;|
Parameter |
Type |
Description |
|---|---|---|
|
valueFromEntry |
(entry: S, index: number) => S |
A function which takes an entry of the original vector and its index, and returns the corresponding entry of the new vector |
Returns:
Vector<S>
The new vector
const original = vectorBuilder.fromValues(1, 2, 3, 4);
const originalPlusOne = original.map(value => value + 1);
// [2, 3, 4, 5]
const originalPlusIndex = original.map((value, index) => value + index);
// [1, 3, 5, 7]