问题
I have a 2D array that I need to save as a property in Google App Script. How would I do this?
var array = [['value 1', 1.0, 'A'],['value 2', 2.0, 'B'],['value 3', 3.0, 'C']]
PropertiesService.getScriptProperties().setProperty('myArray', array)
When I run the code as listed above I get [Ljava.lang.Object;@40ac055f as the value.
When I us array.toString() the property value negates the square brackets.
Thanks in advance!
回答1:
Note that Properties Store is meant to save specific properties and key values. It's not meant to be a replacement for the entire spreadsheet.
Current quotas1 limit the property value size per key to 9kB and total storage per store to 500kB.
If your requirement doesn't cross the limit described above, the easy way is to use JSON.stringify2, Which will convert it to a parsable string.
var array = [['value 1', 1.0, 'A'],['value 2', 2.0, 'B'],['value 3', 3.0, 'C']]; var jarray = JSON.stringify(array); PropertiesService.getScriptProperties().setProperty('myArray', jarray);You can then use JSON.parse3 to retrieve the array
var array = JSON.parse(jarray);
来源:https://stackoverflow.com/questions/53260460/how-to-save-a-2d-array-to-a-script-property-in-properties-service-in-google-app