I would love to learn how to read the MDN documentation. In the 8 years I have been trying, I have taken 35 days off. I still cant understand how to find the base document that gives starters the key to understanding those documents.
In this particular example, there are lots of confusing things. The examples provided compound my confusion.
For starters:
The MDN description says these 3 arguments go into a callback:
- the value of the element
- the index of the element
- the Array object being traversed
The first example after the polyfill explanation is:
function isBigEnough(value) {
return value >= 10
}
let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
// filtered is [12, 130, 44]
So - isBigEnough is “the value of the element”. The value is the name of a function being called [I’m not sure if this is correct].
The index of the element. If the element is a function, then it isn’t an array. How can it have an index. I’m assuming that in this documentation, index is referencing indexOf (from this bit of the documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) [I’m also not sure about this].
Given this is optional, it is not included in the MDN documents example or in the example in the challenge in this tutorial.
indexOf is included in the searching in an array example on the MDN documents, but it is used inside the return value after the filter has been applied, so I’m not sure if it is demonstrating how to use index as an element of the callback.
Finally, item three is the array object being traversed. If the filter is being applied to an array - how could it be unclear which object is being traversed.
The example that uses this argument in the callback in the MDN documents is: Affecting Initial Array (modifying, appending and deleting)
In that example, the array is called words. I don’t understand how that isnt obvious when the filter function is applied to that array. Why is there an element of the callback to identify that array? What is the purpose of its being there?
If I can just figure out how to read these documentary explanations, I might be able to move past this initial phase.
Thank you very much. I am forever indebted to the open source community for the help I have found over the years. If ever I get to a place of understanding, I will pay it forward.