🏠 back to Observable

Confused about return an object in a block


#1

I want to use a block to construct an object, like

data = {
  const cases = xh.getCase({size: 50});
  return cases;
}

It works and return an object like ‘Object {data: Object, warnings: Object}’

But when I want to return ‘data’ field in the block, like return cases['data'] in the block, it returns undefined.

something strange is when I try to use this object in other cell, like data[‘data’], it works…

so I’m confused why I cannot select the filed I want in the block? I’m new to observable notebook, any suggestion will be useful : )


#2

Does xh.getCases return a promise?

If so, try:

data = (await xh.getCases({size: 50})).data

#3

Hi Mike, thanks for your useful information. The problem was solved.
Based on your hint, I checked “Introduction to promise” notebook. My understanding is as one promise could be solved in next cell, when I use it in another cell it works