I want to add a property to the object Array
. I've been trying the following:
Array.prototype.isEmpty = array => (array || []).length <= 0 // only works if I use array.isEmpty(array) which isn't exactly what I want.
Array.prototype.isEmpty = (() => (this || []).length <= 0)() // always returns true since this is always undefined.
Is there a way to add this in JavaScript?