I'm working on the web speech api for my own projects. I'm confused by this function:
colors.forEach(function(v, i, a){
console.log(v, i);
colorHTML += '<span style="background-color:' + v + ';"> ' + v + ' </span>';
});
I understand that v, i & a are parameters, but I can't see where they are declared. They are used in the function and I want to understand how they are used.
Many thanks
Edit: parameters within the parentheses
How do I find parameters declared in a function?
By reading the documentation.
but I can't see where they are declared
They are declared right there in the function expression that creates the function you pass as a callback.
They get values when the function is called.
arr.forEach(callback(currentValue [, index [, array]])[, thisArg])
So v
is the current value being looped over, i
is its index in the array, and a
is the array itself.