为什么我的 for-each 循环没有遍历我的 JavaScript 关联数组对象?
// Defining an array
var array = [];
// Assigning values to corresponding keys
array["Main"] = "Main page";
array["Guide"] = "Guide page";
array["Articles"] = "Articles page";
array["Forum"] = "Forum board";
// Expected: loop over every item,
// yet it logs only "last" assigned value - "Forum"
for (var i = 0; i < array.length; i++) {
console.log(array[i]);
}
jQueryeach()
可能会有所帮助:https ://api.jquery.com/jQuery.each/