gpt4 book ai didi

javascript - 如何打印 2 LL?

转载 作者:行者123 更新时间:2023-11-28 17:25:50 27 4
gpt4 key购买 nike

var str = "ahceclwlxo";
for (var i = 1; i <str.length; i+=2){
console.log(str[i]);
}

在我的浏览器中又出现问题,这里它显示正确的“hello”,但在我的浏览器中它显示“he2Lo”,问题出在哪里?我真的很困惑

最佳答案

您在控制台中看到的是每个 console.log 的出现次数的输出,因此 2l 实际上只是说出现了两次l 正在记录。

控制台输出示例

enter image description here

这又是您的代码,但这次将代码添加到数组中,然后打印该数组。

var str = "ahceclwlxo";
var result = []
for (var i = 1; i <str.length; i+=2){
result.push(str[i])
}
console.log(result)

在 Chrome 的控制台中打印出 (5) ["h", "e", "l", "l", "o"]。表明您有一个长度为 5 的数组。

关于javascript - 如何打印 2 LL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51622477/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com