javascript - Javascript:为什么函数返回时数组长度加倍?
问题描述
我正在尝试用 javascript 编写游戏,并且我想要一个大小为 16 的数组,我可以在不同的函数中更新和返回。这是我到目前为止所拥有的,以及为什么它不起作用。
function startgame(){
var status = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
console.log(status.length);
return status;
}
var status = startgame();
console.log("status length now: "+ status.length);
正如预期的那样,函数内的第一个日志显示 16。但是,函数调用后的第二个日志显示“status length now: 31”。返回的数组正在计算所有逗号。我怎样才能避免这种情况?
解决方案
推荐阅读
- postgresql - PostgreSQL 通过 pgMail 发送电子邮件错误 38000
- ssl - 通过 SSL 连接到 Kafka 的 Filebeat
- python - 在 Python 中向 sftp 子进程发送密码
- here-api - RouteFeatureWeightType 究竟是如何工作的?
- blockchain - 重新派遣功能的费用
- php - PHP Regex - 无法获取可选的命名捕获组
- html - 如何修复我的 htaccess,它将我的页面全部重定向到一个索引
- spring - 如何用 webclient 替换 resttemplate 实现
- google-cloud-storage - 谷歌数据洞察,最大数据限制?
- ionic-framework - 如何获得谷歌 IdToken?