Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 嵌套数组问题_Javascript_Arrays - Fatal编程技术网

Javascript 嵌套数组问题

Javascript 嵌套数组问题,javascript,arrays,Javascript,Arrays,我还没有尝试过javascript中的嵌套数组,所以我不确定它们的格式。这是我的阵列: var items = [ {"Blizzaria Warlock", "105341547"}, {"Profit Vision Goggles", "101008467"}, {"Classy Classic", "111903124"}, {"Gold Beach Time Hat", "111903483"}, {"Ocher Helm of the Lord

我还没有尝试过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]);
…应发出警报
111903124
,但不发出警报。

使用

var items = [
    ["Blizzaria Warlock", "105341547"],
    ["Profit Vision Goggles", "101008467"],
    ["Classy Classic", "111903124"],
    ...
    ["Dragon's Blaze Sword", "105351545"]
];
将阵列构建到阵列中。没有理由更改语法,因为它们在内部。

使用

var items = [
    ["Blizzaria Warlock", "105341547"],
    ["Profit Vision Goggles", "101008467"],
    ["Classy Classic", "111903124"],
    ...
    ["Dragon's Blaze Sword", "105351545"]
];
将阵列构建到阵列中。没有理由更改语法,因为它们在内部。

对象(
{}
)是键值对的集合。您的对象
{“暴雪术士”,“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
可以替换为更具描述性的内容,例如

对象(
{}
)是键值对的集合。您的对象
{“暴雪术士”,“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

您当前正试图将格式错误的对象放入数组中。这是一个非法语法单位数组。对数组数组使用
[…]、[…]、…]
,或对对象数组使用
[{prop:value,…},…]
。您当前正试图将格式错误的对象放入数组中。这是一个非法语法单位数组。对数组数组使用
[…],[…],…]
,或对对象数组使用
[{prop:value,…},…]
。缺少
]
,并且有一个多余的逗号(我假设您只想放第一行,但不太清楚)。缺少
]
,并且有一个多余的逗号(我想你只是想写第一行,但不是很清楚)。