I’ve been encountering this problem a few times. How to add the output from a function, rather than the function itself to an array in JavaScript. Consider the following:
function getRandomValue(){
returns a random number
}
myArray = [getRandomValue(), getRandomValue()];
Is it possible to add just the random numbers and not the function itself to the array?
What you have already does populate the array with the return values of the function:
The parentheses following the identifier cause the function to be invoked, and the return value of it will be placed at the appropriate index of the array.
Were you to remove the invoking parentheses as shown above, you would be populating your array with references to the function, rather than the values returned by it.