0
林有一些問題,在JavaScript中創建對象的數組JavaScript數組 - 如何循環並獲得對象值
請在下面看我的代碼,並告訴我在哪裏,我去錯了..
我只是想遍歷並訪問值
<!-- Read XML Script -->
<script type="text/javascript">
// Object array
var myArray = [];
$(document).ready(function() {
$.ajax({
type: "GET",
url: "HighScore.xml",
dataType: "xml",
success: function (xml) {
$(xml).find('challenger').each(function() {
var name = $(this).find('Name').text();
var watts = $(this).find('Watts').text();
var Mins = $(this).find('Mins').text();
// objects in the array
challenger = new Object();
challenger.name = name;
challenger.watts = watts;
challenger.Mins = Mins;
myArray.push(challenger);
});
// look into the array
for (obj in myArray) {
// do i need to cast ?? how can i view the object ??
alert(obj + " - ");
}
},
error: function() {
alert("error");
}
});
});
</script>
什麼你的意思是「查看對象」?你的意思是你怎麼能用它的屬性來執行'alert'? –
是的,訪問它的屬性:) – JGilmartin