为什么我的数组长度没有增加
why is my array.length not increasing?
通过push添加数组元素不是会使数组的长度增加1吗?
var parameters = [];
if (parameters.length == 0) {
// join select menu and option then add to parameters array
var parameterSelected = nameOfSelectBox + " " + ":" + " " + $i + ",";
parameters.push(parameterSelected);
} else {
var parameterSelected = "," + " " + nameOfSelectBox + " " + ":" + " " + $i;
parameters.push(parameterSelected);
}
// check for repeats
// does a select input exist?
// add to appropriate indexes then add new or modify existing parameters
console.log(parameters.length);
});
在您当前的代码中,它永远不会转到其他地方,因为
var parameters = [];
总是将其长度设置为0,因为您只需再次声明parameters
。然后你在数组中添加一个元素,它的长度变为1,就这样了。
您应该这样做:
var my_array = []; // zero
my_array.push("abc"); // one
my_array.push("def"); // two
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 为什么我的数组长度没有增加
- 为什么在clojurescript中使用nth会使我的代码大小增加74026%
- 我的视图模型不会根据 JSON 结果淘汰来增加数字
- 可折叠面板,增加它'她每次都在我的圈子里
- 我的函数赢得了'Don’不要在文件中增加段落
- 我想编辑一个工作的javascript代码来增加它的功能
- 当使用Javascript克隆表行时,增加我的输入文本id
- 如何防止每次单击按钮时我的代码运行次数增加
- 我的表列在html中自动增加
- 为什么count++在我的情况下不会增加
- 当我将鼠标悬停在Button上以增加它的大小时,它下面的元素会向下移动
- 我如何能增加价值的形式在php
- 为什么我的定时器不增加这个数字?
- 社交插件(facebook, Twitter, Google)增加3秒的加载时间到我的网站.推迟
- 为什么javascript ++操作符在我的代码中增加了不止一步
- 为什么当我在JS中添加动态列表项时,我的标签ID没有增加
- 在我的 jquery 中增加没有工作正常
- 为什么我的node-oracledb执行承诺在解决所需的时间上稳步增加
- 如何添加一个逗号在我的数量增加通过JS