var i = 1;
while(i < 100){
i *= 2;
document.write(i + ", ");
}
所以它写道:
2, 4, 8, 16, 32, 64, 128,
在写入 128 后去掉逗号的最简单方法是什么?
最佳答案
What would the simplest way to take the comma off after it writes 128?
删除输出的最简单方法是不输出它。一种解决方案是在循环开始之前打印第一个值,然后在循环中的值之前写入逗号:
var i = 2;
document.write(i);
while(i < 99){
i *= 2;
document.write(", " + i);
}
关于javascript - 简单 - 从 While 循环输出末尾删除逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60729333/