Q:

Javascript Array Undefined without size

I'm trying to fill an array with a while loop. When I try to read the data at a certain index it keeps giving me undefined yet the length of the array tells me that there MUST be something added.
  var test = [];
  while (i < 16)
  {
    test[i] = i;
    i++;
    console.log(test.length);
    console.log(test[i]);
  }

Console output:
1
Fibbo.html:48 undefined
Fibbo.html:47 2
Fibbo.html:48 undefined
Fibbo.html:47 3
Fibbo.html:48 undefined
Fibbo.html:47 4
Fibbo.html:48 undefined
Fibbo.html:47 5
Fibbo.html:48 undefined
Fibbo.html:47 6
Fibbo.html:48 undefined
Fibbo.html:47 7
Fibbo.html:48 undefined
Fibbo.html:47 8
Fibbo.html:48 undefined
Fibbo.html:47 9
Fibbo.html:48 undefined
Fibbo.html:47 10
Fibbo.html:48 undefined
Fibbo.html:47 11
Fibbo.html:48 undefined
Fibbo.html:47 12
Fibbo.html:48 undefined
Fibbo.html:47 13
Fibbo.html:48 undefined
Fibbo.html:47 14
Fibbo.html:48 undefined
Fibbo.html:47 15
Fibbo.html:48 undefined
Fibbo.html:47 16
Fibbo.html:48 undefined

A:

You are inserting at i and checking the value at i+1.This should fix your code -
  var i = 0;
  var test = [];
  while (i < 16)
  {
    test[i] = i;
    console.log(test.length);
    console.log(test[i]);
    i++;
  }

