Resolving an object in a promise

This seems to work :

let details = [[1,2],[3,4,5],[6,8,9]];
resolve(details);

But this doesn’t :

let details = { name:'John' , age:'40' };
resolve(details);

I’m doing return await new Promise((resolve, reject) in an async function.

The only I got it to work was by doing :

resolve(JSON.stringify(details, null, 2));

Am I missing something here ?

Maybe you should give us an working example. With this few code lines we cannot help. Of course it is not a problem to return an object from a promise.

  1. The object is question is a deeply nested object - not a 1D one
  2. The JavaScript code is actually TypeScript use in Deno, not on client side or nodeJS.

Line 32 of https://anjane.sh/toxicity-webserver

It looks like the resolve function is expecting an array as its input, but in the second example, it is being passed an object. If the resolve function is only able to handle arrays, then the second example will not work as expected. Converting the object to a string using JSON.stringify allows it to be passed to the resolve function, but the function may not be able to handle it properly. It is possible that the resolve function should be updated to handle both arrays and objects, or that the code should be changed to pass only arrays to the function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.