IM麻煩返回包含十進制值到一個變量數組:返回與十進制值的陣列中的JavaScript函數
function foo() {
var coords = new Array(39.3,18.2);
console.log(coords[1]); //successfully logs 18.2
return coords;
}
但隨後...
var result = foo();
alert(result[0]);
即持續一個引發這個錯誤: Uncaught TypeError:無法讀取屬性'0'的未定義
不應該是'alert(result [0])'?其他的一切看起來都很好 - 我會說你的代碼中存在其他問題。 –
這不是問題。我糾正了這個問題。 – andufo