Extending Array.prototype Safely
A helper added to Array.prototype leaks into for...in loops because it is enumerable.
Codejavascript
Array.prototype.last = function () {
return this[this.length - 1];
};
const nums = [10, 20, 30];
let keys = [];
for (const key in nums) {
keys.push(key);
}
console.log(keys); // expected: ['0', '1', '2']What is the bug in this code?