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