Value inside function of an array

var myarray = [function(item){
var item *= 1
return item
}],
[function2(item2)…ect

whats the command to insert value into function(item) thats inside myarray?

something like this:

var myarray = [function(item){
  item *= 1
  return item
}];

console.log(myarray[0](3));

but honestly, this just feels really weird. Why would you do this?

don’t use var in the function, the variable has already been defined (its the parameter)

Thank, just messing around with what i learned to get a better understanding. Thought if i didnt use var it would be scoped global. Does defining it inside the function keep it within its scope?

no, function parameters have a local scope:

function example(par){
   console.log(par);
}

example('hello world');
console.log(par);

That’s not anything new though, is it?

That breaks up into:

How do you look up an element from an array?
How do you call a function?

(Breaking up problems into smaller pieces applies to most problems and is something you should actively be looking for! Solving the subproblems and then combining the results is typically much easier.)

And yeah, looking up a specific function from an array and calling it is weird. If you’re putting something in an array it’s generally because you don’t care about the individual ones, all you care about is having many. So what you would probably do instead is to call ALL the functions in the array, perhaps passing some information through them all.