E
E
exdude2020-05-06 12:24:56
JavaScript
exdude, 2020-05-06 12:24:56

Doesn't define an object property in a loop, what's the reason?

I made a system that defines the city, transfers it to transliteration and is passed as a property of the object for data output. In my case, this is the city, and its mode of operation.
The problem is related to the fact that the property cannot be determined in the loop when loading the thought.
What could be the problem?
If you call through the console, then everything works)
Code: tyk

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PQR, 2020-05-06
@exdude

Your code uses a global variable tow, which is empty at the time getDistr() is called, it has not yet had time to be filled with data from the Yandex.Maps API call.
In general, it is better not to use global variables, but to pass tow directly as getDistr(tow)an argument, and not at the very beginning of the script, but after receiving a response from the API (in the then block).
But I checked using console.log what exactly the call to the Yandex.Maps API returns - it returns an empty string. So in this script, you still need to carefully understand how to work with the Yandex.Maps API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question