Array.prototype.myMap = function(callback) {
const newArray = [];
// Only change code below this line
for(let i in this){
newArray.push(callback(this[i], i, this))
}
// Only change code above this line
return newArray;
};
console.log([1, 2, 3, 4, 5].myMap(item => item * 2))
type here
The result shows like
[ 2, 4, 6, 8, 10, NaN ]
I was expecting the result to be like this:
[ 2, 4, 6, 8, 10 ]
can anyone explain me why I have this null at the end of my arr if I use for in loop
**I know this works with normal for loop but I just wanna know why we get this problem **