Q:

Why does this function with "this" not work? About "this" and its scope

I know that adding a method to the prototype this way is not the best, but I'm just  testing.

Array.prototype.maap = function (transform) {
  let mapped = [];
  for (let element of this) {
        mapped.push(transform(element));
  }
  return mapped;
}

console.log([0, 2, 3].maap(n => n / this.length));

I am getting:
[NaN, Infinity, Infinity]. I think the problem is "this.length".

A:

You're right, the problem is this.length. The trouble is that it's not in the function! It's in a lambda, whose scope is not that of the array by which it's later invoked. As such, this is not the array, and this.length is a solid 0 (0/0 being NaN, 2/0 being infinity and 3/0 also being infinity).
You can either hardcode the real value 3, or move your logic into the function itself. Or you could have the lambda (actually an "arrow function" in JavaScript) take another parameter: that of the denominator.

Array.prototype.maap = function (transform) {
  let mapped = [];
  for (let element of this) {
        mapped.push(transform(element, this.length));
  }
  return mapped;
}

console.log([0, 2, 3].maap((n, m) => n / m));

