A way with the standard cycle:
var a = [, , , 6, undefined, , 5, , null, 7]; for (var i = a.length - 1; i > -1; i--) { if (!(i in a)) a.splice(i, 1); }
undefined and null are not removed as expected.
undefined
null