Unable to use async-await in array filter!
I tried to create array and iterate using filter to add if a response is success
var awardCodes = [1, 2, 3, 11];
function getPosts() {
const response = fetch("https://jsonplaceholder.typicode.com/user");
return response;
}
function test(awardCodes) {
var arr = awardCodes.filter(checkCode);
console.log(arr, awardCodes);
}
var checkCode = async (code) => {
try {
let res = await getPosts();
if (res.status == 200) {
console.log("true");
return true;
} else {
console.log("false1");
return false;
}
} catch (error) {
console.log("false2");
return false;
}
console.log("false3");
return false;
}
test(awardCodes);
I expect the output to be an empty array
.filteranasyncfunction, which always returns a Promise.for ofetc instead.checkCodepredicate doesn't even make much sense - it takescodeas parameter but never uses it within the body. What is the intention here?