🏠 back to Observable

array.map is only a function in another cell

i have 3 cells:

A: gets data from an IndexDB via its JS API query = flux => QueryAPI.collectRows(flux)

B: provides a flux Query to execute via A and assigns the result to a variable data = query('from(… <query>')
The cell Return value is an Array

C: Transforms data via array.map

I wanted to combine Cells B and C so data = query(…).map(…) and i get the error undefined is not a function

i cant fathom why moving code from within a cell to a separate cell would yield such an error. Maybe some async/promise magic? but adding an await before function calls only puts out more errors.

yes, maybe (await query(...)).map(...), or equivalently query(...).then(d => d.map(...))

The “magic” when separating in different cells is that every cell is “awaited” automatically, so that if the cell contains a Promise, its value will be the resolved or rejected value. See https://observablehq.com/@observablehq/introduction-to-promises?collection=@observablehq/javascript-in-observable for example.