Convert what looks like a number but isn't to an integer (Google Earth Engine)

Viewed 3356

I'm trying to get the number of images in an image collection in the Google Earth Engine (GEE) code editor. The image collection filteredCollection contains all Landsat 8 images on GEE that cover Greenwich (just an example).

The number of images is printed as 113 but it doesn't appear to be of type integer and I can't coerce it to an integer either. Here's what that looks like:

var imageCollection = ee.ImageCollection("LANDSAT/LC8_SR");
var point = ee.Geometry.Point([0.0, 51.48]);
var filteredCollection = imageCollection.filterBounds(point);

var number_of_images = filteredCollection.size();
print(number_of_images); // prints 113
print(number_of_images > 1); // prints false
print(+number_of_images); // prints NaN
print(parseInt(number_of_images, 10)); // prints NaN
print(Number(number_of_images)); // prints NaN
print(typeof number_of_images); // prints object
print(number_of_images.constructor); // prints <Function>
print(number_of_images.constructor.name); // prints Ik

var number_of_images_2 = filteredCollection.length;
print(number_of_images_2); // prints undefined

Any idea what's happening here and how I can get the number of images in the collection as an integer?

P.S.: Collection.size() is the recommended function for getting the number of images in the GEE docs.

1 Answers
Related