Borgher
Borgher

Reputation: 315

Formatting text (from array) on prompt window

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

Upvotes: 0

Views: 30

Answers (1)

Tanaike
Tanaike

Reputation: 201603

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:

Upvotes: 2

Related Questions