var arr = Array(); arr[0] = 0; arr[3] = 3; arr[4] = 4; function get(arr, num) { arr.filter(function (el) { return el !== void(0) }) return arr.splice(num, 1); } alert(get(arr, -2));