Deleting elements from an JavaScript array and closing up the gaps