英文:
Formatting text (from array) on prompt window
问题
以下是要翻译的代码部分:
const arr = [1, 2, 3, 4, 5, 6];
function alertMessage() {
SpreadsheetApp.getUi().alert(`数字列表:\n${arr.join('\n')}`);
}
alertMessage();
希望这对你有所帮助。
英文:
I have a very simple prompt that outputs elements from an array:
const arr = [1, 2, 3, 4, 5, 6];
function alertMessage() {
SpreadsheetApp.getUi().alert(`List of numbers: ${arr}`);
}
alertMessage();
The message currently reads like this:
List of numbers: 1,2,3,4,5,6
However, I would like it to create a new line after each element (with no commas), so it would look like the below example. What would be the best way to do this?
List of numbers:
1
2
3
4
5
6
答案1
得分: 2
从:
SpreadsheetApp.getUi().alert(`数字列表: ${arr}`);
到:
SpreadsheetApp.getUi().alert(`数字列表: \n${arr.join("\n")}`);
- 如果您想要双行间隔,请修改为
SpreadsheetApp.getUi().alert(
数字列表: \n${arr.join("\n\n")});
参考:
英文:
It seems that in your script, arr
is an array. So, how about the following modification?
From:
SpreadsheetApp.getUi().alert(`List of numbers: ${arr}`);
To:
SpreadsheetApp.getUi().alert(`List of numbers: \n${arr.join("\n")}`);
- If you want the double line breaks, please modify to
SpreadsheetApp.getUi().alert(
List of numbers: \n${arr.join("\n\n")});
Reference:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论