I'd like to know how to add a custom function to the array object using prototype.
I called my function get. get takes an index and returns the element from the array with that index. It's pointless i know, but im using it for educational purposes.
So this is how it'd look like using it.
const a = ['1' , '2' , '3'];
a.get(2) -----> returns '3'
This is what i've tried.
Array.prototype.get = index => {
return this[index];
};
let a = ['1','2' ,'3'];
console.log(a.get(1));
This returns undefined to me.