JavaScript - extremely confused on removing elements from Container

后端 未结 4 1321
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 05:47

I\'m making a 2D, top-down Zelda style web rpg single player in JavaScript.

When the player (purple shirt) walks near a cat, it will \"rescue\" it... which basically rem

4条回答
  •  半阙折子戏
    2021-01-25 06:25

    It may be possible that your rescuedTotal_Array is an associative Array (or was morphed to one) and could contain something like:

    rescuedTotal_Array = [1:object,2:object,object:object]
    

    The array above has the length of 3. But you cannot access the third element via index 2, because its index is some kind of object.

    Try to dump the content of your rescuedTotal_Array before accessing it (so you can see if everything is ok). This is not a solution, but it may help you so that you can find the error by yourself. Use something like

    for (index in rescuedTotal_Array) {
        if (rescuedTotal_Array.hasOwnProperty(index)) {
            console.log(rescuedTotal_Array[index]);
        }
        else {
            console.log("no entry found for index: "+index);
        }
    }
    

提交回复
热议问题