function toObject(arr) {
var res = {};
for (var i = 0; i < arr.length; ++i)
if (arr[i] !== undefined) res[i] = arr[i];
return res;
}
...
$array.push(e.target.id);
...
$obj = toObject($array);
...
jQuery.ajax({
url: 'upload.php',
type: "POST",
data: $obj,
...
$obj = $.extend({}, $array);