I'm using Google Earth Engine for a GIS project and I'm extracting an average density from a WorldPop layer and for a precise area defined by a geometry. Further in my code, I want to use this average density as a float, here is my code :
// Layer used for population density
var datapop = ee.ImageCollection("WorldPop/GP/100m/pop").mosaic().clip(geometry_pop) ;
// Average, max and minimum population density for the selected area
var density = datapop.reduce(ee.Reducer.first()).reduceRegion(ee.Reducer.mean(),geometry_pop,100).get('first');
I've tried some prints to see what was the type conversion problem :
print(typeof density) //prints JSON object
print(typeof parseFloat(density)) //prints JSON number
var test = 9.0 ;
print(typeof test) //prints JSON number
print(density) //prints 9.960041574584405
print(parseFloat(density)) //prints NaN
Does someone know how can I convert my JSON object into a JSON number without getting its value to NaN ?