fsp712
fsp712

Reputation: 37

How to pass an extra parameter to function in map Javascript

If I have something like this:

dataArray.map(self.aggregationFunction);

but I want to pass the aggregationFunction another parameter, is this possible in Javascript? I tried adding .bind(extra parameter) but it didn't seem to work. Thanks!

Upvotes: 0

Views: 71

Answers (1)

aoldershaw
aoldershaw

Reputation: 131

Rather than passing the function directly, you could pass in a function which calls the function with the additional parameter, e.g:

let someOtherValue = 123;
dataArray.map((dataItem) => aggregationFunction(dataItem, someOtherValue))

Upvotes: 2

Related Questions