Implement map on a Prototype

I couldnt figure this out my code is as follows below. Why does the callback function take three arguments (this[i], i, this) I just used this[i] as the callback but it doesnt work.

Array.prototype.myMap = function(callback) {
  const newArray = [];
  // Only change code below this line
for (i=0; i < this.length; i++){
  
  newArray.push(callback(this[i]))
}
  // Only change code above this line
  console.log(newArray)
  return newArray;
};

When the callback is used, it is passed three arguments. The first argument is the current element being processed. The second is the index of that element and the third is the array upon which the map method was called.

Iā€™m going to have to think that one over and read up on this again

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.