« first day (2867 days earlier)      last day (1235 days later) » 

2:45 PM
Hello,

Can anyone help me why prototype using arrow function does not work, but works with ES5 syntax?

My code:

```
// Print a random number from an array (Using ES5 syntax)
Array.prototype.random = function() {
return this[Math.floor((Math.random() * this.length))];
}

let arr = [1, 2, 3, 4, 5]
console.log(arr.random()) // Prints random number


// Using ES6 syntax
Array.prototype.random = () => {
return this[Math.floor((Math.random() * this.length))];
}


let arr1 = [1, 2, 3, 4, 5]
console.log(arr1.random()) // Prints undefined
 
2:59 PM
1 message moved from JavaScript
 
3:54 PM
please help me to resolve this issue stackoverflow.com/questions/65075693/…
 
@user10153776 Welcome to the Java Chat, the room for Java enthusiasts! I'm Oak, one of the room's bots. If you want to ask a question, just ask it and someone will respond if they feel like it. But remember that this room is not a help desk or tutoring service! If you want to just hang out, then welcome aboard! Oh, and the room's full list of rules are posted here.
 
 
1 hour later…
Zoe
4:56 PM
@user10153776 Please don't use chat as fastlane for your questions. Instead, wait a few days before asking here to give the people on the main site some time. If we want to answer questions there, we will look for them on our own.
3 messages moved from Java
 
 
2 hours later…
6:29 PM
Hi all :)
 
7:00 PM
1 message moved from HTML / CSS / WebDesign
 

« first day (2867 days earlier)      last day (1235 days later) »