async function successA(){return 'A'}
async function successB(){return 'B'}
async function failC(){throw 'error c'}
async function failD(){throw 'error d'}
const results = await Promise.allSettled([
successA(),
successB(),
failC(),
failD()
])
const successfullResults = results
.filter(result => result.status === "fulfilled")
.map(result => result.value)
console.log(successfullResults)
results
.filter(result => result.status === "rejected")
.forEach(error => console.log(error.reason))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter