1

I think I'm fundamentally misunderstanding something here in Javascript.

Could someone please explain why I get SyntaxError: Unexpected identifier when trying to call getUrlContent from inside the forEach:

(async () => {

    let sitesState = []
    urlsToCheck.forEach(url => {
        sitesState.push({
            "url": url,
            "data": await getUrlContent(url)
        })
    })

})();

async function getUrlContent(url) { ... }

Why does this happen (and of course, how do I write this correctly?).

Any help appreciated.

Thanks.

2

1 Answer 1

1

You've used async in the wrong function. Check this.

    ( () => {

    let sitesState = []
    urlsToCheck.forEach(async(url) => {
        sitesState.push({
            "url": url,
            "data": await getUrlContent(url)
        })
    })

})();

async function getUrlContent(url) { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.