我还没有尝试过javascript中的嵌套数组,所以我不确定它们的格式。下面是我的数组:
var items = [
{"Blizzaria Warlock", "105341547"},
{"Profit Vision Goggles", "101008467"},
{"Classy Classic", "111903124"},
{"Gold Beach Time Hat", "111903483"},
{"Ocher Helm of the Lord of the Fire Dragon", "111902100"},
{"Greyson the Spiny Forked", "102619387"},
{"Egg on your Face", "110207471"},
{"Evil Skeptic", "110336757"},
{"Red Futurion Foot Soldier", "90249069"},
{"Wizards of the Astral Isles: Frog Transformer", "106701619"},
{"Dragon's Blaze Sword", "105351545"}
];
alert(items[2][1]);...which应该提醒111903124,但没有。
发布于 2013-04-20 04:00:49
使用
var items = [
["Blizzaria Warlock", "105341547"],
["Profit Vision Goggles", "101008467"],
["Classy Classic", "111903124"],
...
["Dragon's Blaze Sword", "105351545"]
];将数组构建为数组。没有理由改变语法,因为它们就在里面。
发布于 2013-04-20 04:04:53
对象({})是键-值对的集合。您的对象{"Blizzaria Warlock", "105341547"}包含值,但不包含键。也许更好的方法是为这些属性指定描述性名称,然后按属性名称引用这些项:
var items = [
{name: "Blizzaria Warlock", val: "105341547"},
{name: "Profit Vision Goggles", val: "101008467"},
{name: "Classy Classic", val: "111903124"},
{name: "Gold Beach Time Hat", val: "111903483"},
{name: "Ocher Helm of the Lord of the Fire Dragon", val: "111902100"},
{name: "Greyson the Spiny Forked", val: "102619387"},
{name: "Egg on your Face", val: "110207471"},
{name: "Evil Skeptic", val: "110336757"},
{name: "Red Futurion Foot Soldier", val: "90249069"},
{name: "Wizards of the Astral Isles: Frog Transformer", val: "106701619"},
{name: "Dragon's Blaze Sword", val: "105351545"}
];
alert(items[2].val);可以用更具描述性的东西来代替val,比如points。
https://stackoverflow.com/questions/16112636
复制相似问题