【发布时间】:2018-11-10 16:43:29
【问题描述】:
我的代码是这样的:
var allcategories = ["category1", "category2", "category3"];
var category1 = ["item1", "item2", "item3"];
var category2 = ["item4", "item5", "item6", "item7", "item8"];
var category3 = ["item9", "item10"];
for (let currentcategory of allcategories) {
for (let categoryitem of currentcategory) {
console.log (currentcategory, categoryitem);
};
};
“allcategories”变量中列出的每个项目也是一个包含已保存项目的变量。 我的目标是获取变量“category1, category2 category3 ...”的值,但这仅返回变量的第一个字母(“C”)。 知道我做错了什么吗?
【问题讨论】:
-
allcategories的字符串常量和下面3行的数组对象不一样
标签: javascript arrays object for-loop