Skip to content
Advertisement

I keep getting undefined after async call in another function

I Have 2 functions one which uses async and await to grab data and place it into an array. The second is acts like a checker to see if the user inputs a similar value as seen on the database

JavaScript

When I compile a simple if statement everything returns true and when I do console.log(test[0]) it returns undefined?

Advertisement

Answer

repeatChecker isn’t returning a promise, so the fact that you’re awaiting doesn’t have any meaningful effect. console.log(test[0]) executes before api_data_values.push(data[i].name).

Try this:

JavaScript

Or with async/await:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement