I'm trying to get an array's length and display it on a page, like so:
var someArray = ['item 1', 'item 2', 'item 3'];
var getArrayLength = function() {
return someArray.length;
}
getArrayLength();
For some reason this isn't working. I tried to replace the element's innerHTML, same issue.
<p id="demo"></p>
document.getElementById("demo").innerHTML = someArray.length;
Even if I set a variable equal to someArray.length and then return the variable it doesn't work. I don't get any errors, just no result. Is there something special about returning the length of an array in a function?
I was able to pull this off using jQuery, I'm just curious as to what I was doing wrong with the vanilla javascript.
pelement?