Functional Programming: Implement map on a Prototype (in vs. of)

Could someone give a brief overview of why NaN is added to this return? Aren’t these doing the same thing?


Array.prototype.myMap = function(callback){
  var newArray = [];
//option 1. works properly
  for(var item "of" this) {
    newArray.push(callback(item));
  }
//option 2 adds NaN
for(var item "in" this) {
     newArray.push(callback(this[item]);
}


  return newArray;

};

var new_s = s.myMap(function(item){
  return item * 2;
});
console.log(new_s); //using option 2

// returns [0,2,4,6,NaN]```

Thank you.

w3Schools Javascript loops:
* `for`  - loops through a block of code a number of times
* `for/in`  - loops through the properties of an object
* `for/of`  - loops through the values of an iterable object
* `while`  - loops through a block of code while a specified condition is true
* `do/while`  - also loops through a block of code while a specified condition is true

what’s s value? or what’s the challenge link? can’t test without one of those

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype

apologies…

try adding console.log(item) in both cases and see what comes out.

This is more comprehensive, in short for…in is iterating over other properties, like the myMap property that you have just created there.