【发布时间】:2021-06-20 21:07:48
【问题描述】:
如何在javascript中打印如下?
如果我的输入是“智能” 那么我的输出可能是“s,m,a,r,t”
我已尝试使用此逻辑,但我得到的输出为 s,m,a,r,t,
let a = " ";
str = userInput[0];
console.log(str);
for (let i = 0; i < str.length; i++) {
a = a + str[i] + ",";
}
console.log(a.trim());
【问题讨论】:
-
'smart'.split('').join()? -
欢迎来到 Stack Overflow!欢迎来到堆栈溢出!访问help center,使用tour 了解内容和How to Ask。请首先>>>Search for related topics on SO,如果您遇到困难,请发布您的尝试的minimal reproducible example,并使用
[<>]记录输入和预期输出sn-p 编辑器。 -
const a = userInput[0]?.trim().split("").toString() || "" -
@Angeshwari 随意删除这个巨大的骗局
标签: javascript