Using javascript map with a function that has two arguments

I know that I can use map with a function of one variable in the following manner:

var squarefunc = function(x) {
    return x*x;
};
values = [1,2,3,4]
values.map(squarefunc) // returns [1,4,9,16]

How do I use map with the following function:

var squarefuncwithadjustment = function(x, adjustment) {
    return (x*x + adjustment);
}

where, I want to input value for argument adjustment manually when I call map, say adjustment=2, and have the value of x taken from the array values.

Answers


Use an anonymous function:

values.map(
  function(x) { return squarefuncwithadjustment(x, 2); }
);

Need Your Help

How to pass javascript string variable as a real setting?

javascript string variables dynamic

I have a javascript question. I'm trying to dynamically build a plugins string variable (optPlugins) and insert into a setup for jwplayer but it doesn't work. For example: