【发布时间】:2012-07-05 12:49:28
【问题描述】:
我想知道为什么我在 pages 对象(见下文)中的 pageCounter 被视为字符串而不是 int?
为什么javascript不解释变量,而是把变量名当作文字字符串使用?
for (var i in stories){
//reset the counter when it hits the number of stories per page
if (counter >= divsByPage) {
counter = 1;
pageCounter++;
}
//turn all the stories off
//stories[i].style.display = "none";
//insert a new story under a page array
pages.push({pageCounter:stories[i]});
counter++;
}
console.log(pages[1]); 输出Object { pageCounter=[1]}。
【问题讨论】:
-
是什么让你认为它是以字符串形式出现的?
-
我想得到类似的最终结果:
[{0:[{story}, {story}, {story}], 1:[{story}, {story}]}];
标签: javascript string object counter