function clearArrayFromUndefined(){
var i = 0;
do {
if(array[i] === undefined) array.splice(i, 1);
else i++;
} while (i < array.length);
}
var array = [];
array[0] = 0;
array[1] = 1;
array[3] = 3;
array[5] = 5;
array[8] = 8;
array[15] = 15;
array[20] = 20;
//array[50] = 50;
console.log(array);
clearArrayFromUndefined();
console.log(array);