Map on prototype challenges

Tell us what’s happening:
Describe your issue in detail here.
Could someone explain to me why and how this is used in the solution to the challenge. I have failed to understand how this comes in here

  **Your code so far**

// The global variable
const s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line

// Only change code above this line
return newArray;

const new_s = s.myMap(function(item) {
return item * 2;
  **Your browser information:**

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1

Challenge: Implement map on a Prototype

Link to the challenge:

Please post your code instead of bad pictures… Thanks.

I haven’t written any code. I was simply looking at the solution and didn’t understand it. Thanks

Ok… Please link or post the solution instead of bad pictures that are unreadable…

I’d recommend ignoring the solution and trying to build your own instead of copying the solution. The projects won’t have solutions for you to copy.

The challenge says

The Array instance can be accessed in the myMap method using this.

So, you use the keyword this to access the array when adding a method to the Array prototype.

I was under the impression that this only works with objects not arrays
Thank you

Arrays are actually a type of object.

1 Like

I get it now. Thank you

1 Like

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