I'm recreating Javascript's map function and i'm not understanding where these parameters are coming from:
(this[index], index, this)
I understand what this is the array, i understand this[index] is the value, and index is the number that keeps track of the index on iteration, but where is that all coming from when i'm only passing in:
x => x * 5
that's the part i'm confused about and havne't found a good explanation about it online.
Array.prototype.mymap = function(callback) {
const resultArray = [];
for (let index = 0; index < this.length; index++) {
resultArray.push(callback(this[index], index, this)); // confused about these parameters
}
return resultArray;
}
const sample = [1,2,3];
var output = sample.mymap(x => x * 5);
console.log(output);