I have array and want access by property (not function) like:
let arr = [1,2,3];
console.log("last element: ", arr.last)
I try like it, but got error:
Array.prototype.last = (() => {
return this[this.length - 1];
})();
Update 1: yes i know how do it like extend method:
Array.prototype.mysort = function() {
this.sort(() => Math.random() - 0.5);
return this;
}
myarray.mysort();
but how do it like property?
myarray.mysort;