在提示窗口中格式化文本(来自数组)

huangapple go评论52阅读模式
英文:

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:

huangapple
  • 本文由 发表于 2023年2月10日 10:53:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定