I'm using the Javascript console on Google Earth Engine, and I'm stumped by a simple problem. I want to concatenate and print two values on one line. One of them is an object property.
When I use a comma to separate the parts in the print statement, I get the output I want, except that it is printed on separate lines. When I use a plus ('+'), the object's toString
method is invoked and I get vastly more output than I want.
var img = ee.Image(img_list.get(0)) //grab an image
var date_index = img.get('system:index'); //get its date index property
print('MOD13Q_', date_index);
//Output (basically what I want, except on two lines instead of one)
//'MOD13Q_'
//'2018-01-17'
print('MOD13Q_' + date_index); //Oops, '+' invoked the toString method
//'MOD13Q_ComputedObject({
"type": "Invocation",
"arguments": {
"object": {
"type": "Invocation",
"arguments": {
"list": {
"type"....etc.
Is there any way to override the toString
method, or to prevent it from being invoked? This question describes something similar, but does not show how to solve my problem.
print(date_index)
(where date_index is an ee Object) is a shortcut of print(date_index.getInfo()). You can still use your second print statement using the + operator, but you have to use .getInfo():print('MOD13Q_'+date_index.getInfo())