I'm getting two extra/unexpected array entries that are undefined. These show up when I iterate over an array of element nodes with 3 entries and push the values into another array:
I have a select element with 4 options in it. I want to put the last 3 options.innerText into an array
<select>
<option>skip me</option>
<option>text1</option>
<option>text2</option>
<option>text3</option>
<select>
I made a variable and grabbed the nodes:
var options = document.querySelectorAll('select option:not(:first-child)')
this gave me an array with 3 option elements in it as confirmed in the console
>>options
<<[<option>text1</option>,
<option>text2</option>,
<option>text3</option>]
options.length is 3.
iterating over the array proceeds as expected, but also includes a function in the log?
>>for (i in options){console.log(options[i])}
<< <option>text1</option>
<option>text2</option>
<option>text3</option>
<< 3
<< function item() {[native code]}
When I iterate over the array and push the innerText into a new array, I get not 3, but 5 entries in the array
>>var texts = [];
>>for (i in options){texts.push(options[i].innerText)}
This gives me an array texts with 5 values: ['text1','text2','text3',undefined,undefined]
texts.length is 5
Why am I getting those two extra array entries?
I'm sure this is something elementary that I just haven't come across yet, can anyone explain?