Incoming "noob" question:
Javascript has an includes
method on arrays.
It looks like:
Array.includes()
But when I go to the Javascript Manual to understand this method, the heading on that page (for an appropriate technical reason, I realize) is:
Array.prototype.includes()
Similar things in the Javascript Manual have caused me to not like the manual at all (and alas, I rely on W3Schools more than the manual).
However, I really really want to learn to interpret the manual.
So, my question is: what's the significance of including the word .prototype
in Array.prototype.includes()
in the documentation, when the actual usage looks like: Array.includes()
?
(Also, if anyone has suggestions on how I can improve my comprehension of the official Javascript Manual, I'd appreciate suggestions.)
If the documentation said Array.includes()
you would literally type it like this (example):
Array.includes(1);
Instead it says Array.prototype.includes()
which means it isn't called on the Array
type itself, but on an instance of it. So in this case you would write:
const numbers = [1, 2, 3];
numbers.includes(1);