how to remove the even listener after the array is finished