Evelate,
function clearArrayFromUndefined(arr){
for (var j = 0; j < arr.length; ) {
var n = arr[j];
if (n === undefined) {
for (var k = j; k < arr.length-1; k++) {
arr[k] = arr[k+1];
}
arr.length--;
}
else j++
}
return arr;
}
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(array);
console.log(array);