An async function I am dealing with, returns multiple values in array
const funcName = async function (arg) {
...
return [val1, val2];
}
While calling this function, I find that it is not possible to directly access individual return values in a syntax:
result1 = await funcName(arg)[0]
result2 = await funcName(arg)[1]
The only way (known to me so far) it works, is to break it down:
result = await funcName(arg)
result1 = result[0]
result2 = result[1]
Is there a way to "collect" the return directly in a single LOC?
(closely, like r1 = await fn(x)[0]
)
This works obviously for sync variant, and keeps code much precise, clean, while readable.
Bonus ask: any clue why direct array access is not supported?
By intent, or just missed out?