The first element that was found in the array, or null if the array was empty.
Notes:
* The usefulness of this method is rather limited, as it does not have any added value over Array''[0]''. Its main purpose is to allow for an alternative syntax, which under certain situations may improve readability.
===== Examples =====
A simple example could look like this:
let foo = document.getElementsByTagName('foo');
let bar = foo.first();
if (bar) {
…
}
Or, if you don’t need a reference to the element, you can use a more compact form like:
if (document.getElementsByTagName('foo').first()) {
…
}
===== More information =====
* [[mdn>Web/JavaScript/Reference/Global_Objects/Array/length|Array: length]] on MDN.