I created an array using:
var links = document.getElementsByTagName('a');
If I do:
console.log(links.length);
I get: 2.
However, if I do:
console.log(links);
I get an object that looks like this:
[a.elm-skip-link, a]
and when I expand this object, there are 33 link objects in it.
Why does the length of the links object change? If it is an array, doesn't it retain the size it is when created?
Here is all the code I'm using:
var links = document.getElementsByTagName('a');
console.log('links:');
console.log(links);
console.log('length:');
console.log(links.length);
BTW: I'm trying to select a specific link on the page that does not have an "id" or "class" attribute, so I'm needing to get all the links, then loop through them to find the one that has the "title" attribute I'm looking for. However, when I try to loop through this "links" object, the loop only runs twice, despite there being 33 links on the page.