Implement map on a Prototype..Help

Tell us what’s happening:
What does this stand for here ?

Your code so far

// the global Array
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
  var newArray = [];
  // Add your code below this line
  this.forEach(a => newArray.push(callback(a)));
  // Add your code above this line
  return newArray;


var new_s = s.myMap(function(item){
  return item * 2;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:

this refers to the object that the .myMap method/function is associated with. In this particular case, this refers to the array (s) on which .myMap is called.

So this refers to [23, 65, 98, 5].

You can look back at this challenge for the first mention of this.

1 Like

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

Thank you for mentioning, I was wondering why did that happen. I will see to it next time.

Thank you. That clarified my query.