Here's a small JavaScript snippet:
var re_words = /\w+/g;
var words;
while (words = re_words.exec(' here are a few (sic!) words ')) {
alert(words);
}
The loop alerts the words found in the input string, which is what I expected, because all the JavaScript tutorials tell me so.
Now, typeof(words) results in object.
Therefore, I would have expected alert(words) to give me object.
If I inspect the elements in words, I found them to be 0, "index" and "input". The element words[0] is the same as what is alerted with words.
So, the question is: is the element 0 sort of a default index for an Object in JavaScript which is returned if it is defined.
Or asked differently: why does alert(words) give the same effect as alert(words[0])? I would have expected alert(words) to give a "Object".