Q:

How to pass an array through a prototype?

Whenever I try to pass an array through a prototype, I always get an error.
I want to start passing an array into prototypes. But, I do not know how.
The results for the demo should log false

String.prototype.isGreaterThan = function(n) {
  return this.length > n
}


myArray = ["one", "two", "three"]
a = myArray.isGreaterThan(5)




console.log(a)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

A:

myArray is an array but not string whereas the prototype method is added to String data type instead of Array.Change it to Array.prototype.isGreaterThan

Array.prototype.isGreaterThan = function(n) {
  return this.length > n
}

let myArray = ["one", "two", "three"]
a = myArray.isGreaterThan(5)
console.log(a)

