-1
sorted = Object.keys(PLAYER_LIST).sort(function(a,b){return a.score - b.score}); // have key value
console.log(PLAYER_LIST[sorted[0]].team); // result:"A"
for(var loop=0; loop<=sorted.length; loop++) {
if(PLAYER_LIST[sorted[loop]].team == "A") { // error
some code...
}
}
當我這樣排序。 console.log運行良好。但是如果判決不起作用。我收到錯誤消息。我不知道爲什麼。請幫幫我。在node.js訪問屬性
if(PLAYER_LIST[sorted[loop]].team == "A") {
^
TypeError: Cannot set property 'team' of undefined
太感謝你了!!!!!!! – firepunch
我可怕的錯誤.. :( – firepunch