fix in javascript for the case that the first pin gets deleted from the array, before it could happen that the array was empty or the index was -1 or both