I’m just learning JavaScript and I’m trying to do the following. Let’s say I have the following function:
f(a,b) {return(a+b)}
And now I have a list of for example the following:
list = [1,2,3]
What I would like to do is map for that list in which I call the function above f with a predefined value and each value of the list. I’ve tried this:
listB = list.map(x => f(x+23))
But it returns a NaN, and if I add some brackets that snippet returns undefined.
What’s going on and how can I solve it?
>Solution :
Should be f(x, 23) instead of f(x + 23):
function f(a,b) {return(a+b)}
listA = [1,2,3]
listB = listA.map(x => f(x,23))
console.log(listB)