【发布时间】:2013-11-06 22:48:39
【问题描述】:
我有一个这样的数组:
elements = {
opinions: ['p31/php/endpoint.php?get=opinions'], // function to call and API endpoint, php/endpoint.php
top3positive: ['p31/php/endpoint.php?get=top3positive'], // function to call andAPI endpoint, php/endpoint.php
top3negative: ['p31/php/endpoint.php?get=top3negative'], // function to call andAPI endpoint, php/endpoint.php
};
如何指向第一个数组。如果我这样做alert(elements[0]);,它不会像我期望的那样返回意见。
我做错了什么?
我需要根据它的顺序 0,1,2 等指向数组索引。
谢谢
【问题讨论】:
-
{}表示法用于对象,而不是数组。你通过elements.opinions访问opinions。 -
@whatyouhide 如果我需要按数字访问索引怎么办?如何将其转换为数组?
-
我在这里发布了一个解释对象/数组混淆的答案。
-
这个 w3school 网页展示了很多在 javascript 中使用数组的示例:w3schools.com/js/js_obj_array.asp
标签: javascript