I understand how array filter works and that the filter helper function takes a callback function that takes one mandatory argument (element) and two optional ones (index, array). However, it's confusing to understand this based on how the MDN documentation describes it:
let newArray = arr.filter(callback(element[, index, [array]])[, thisArg])
It seems as if it would be more clear if it was just:
let newArray = arr.filter(callback(element, index, array), thisArg)
Questions that I have regarding the way MDN has it are:
- element is the first argument to the callback followed by an array without a comma separating the two, why is this?
- Why is index and [array] nested within another array?
- What is the significance of the comma that this array starts with?