gpt4 book ai didi

javascript - 如何更改字符串的输出?

转载 作者:行者123 更新时间:2023-12-03 09:01:57 24 4
gpt4 key购买 nike

如何左对齐字符串的输出?我正在尝试打印第一封电子邮件,在下一行打印下一封,等等

<html>
<body>
<p id="demo"></p>

<script>

//The email list
var emailList = ["adam@yahoo.edu\n", "henry@yahoo.edu\n", "john@yahoo.edu\n", "sally@yahoo.edu\n", "adam@yahoo.edu\n", "david@yahoo.edu\n", "myhome@yahoo.edu\n", "david@yahoo.edu\n", "david@yahoo.edu\n", "hunger@yahoo.edu\n", "madison@yahoo.edu\n"];

//remove the yahoo extension
var emailUserHash = emailList.reduce(function(emailUsers, email, i) {
var username = email.slice(0, email.indexOf('yahoo'));
if(!emailUsers[username]) emailUsers[username] = true;
return emailUsers;
}, {});

//call the emailUserHash function
var emailUsers = Object.keys(emailUserHash)

//sort the email list
emailUsers.sort();

//output the list
document.write(emailUsers.join(', '));
</script>
</body>
</html>

最佳答案

你只需要修改你的 join()

使用“/r/n”在这里不会有帮助

document.write(emailUsers.join('/r/n'));

所以你可以使用 'br' 这肯定会起作用。

document.write(emailUsers.join('</br>'));

关于javascript - 如何更改字符串的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32280164/

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