Reputation: 119
I am looking for a way to make a cell equal to an entire array in Google Apps Script and Google Sheets.
I have tried making the cell.setValue(array) but using this method the cell is equal to the first array item only.
var cell = SpreadsheetApp.getActiveSpreadsheet().getRange("A1").getValues();
var array = ["Item one", "Item two", "Item three"];
cell.setValue(array)
I want the cell to equal "Item one, Item two, Item three" but the cell equals to "Item one" using that method.
Upvotes: 2
Views: 72
Reputation: 156
You can use toString()
var array1 = [1, 2, 'a', '1a'];
console.log(array1.toString());
// output: "1,2,a,1a"
From: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Array/toString
Upvotes: 2
Reputation: 222
You could convert the array to a string beforehand with Array.join
cell.setValue(array.join(", "));
Upvotes: 3