You can use await keyword in another async function to get the desired result via - (await getArray())[0].
If you use async function not inside another async function, it must be used like simple Promise function with calling then.
var getArray = async function(id) {
return [1,2];
}
getArray().then(res => console.log(res[0])).catch(err => {/* ... */});
If you want to use await, you need another wrapper async function which will do the logic there and will be just called. Also you can use try/catch within your function
var getArray = async function(id) {
return [1,2];
}
async function printFirst() {
try {
const first = (await getArray())[0];
console.log(first);
} catch(e) {
}
}
printFirst();
awaitoutside of anasync function. Wherever you callgetArray, make thatasyncas well