A
A
Alexander Ivanov2019-05-02 11:50:04
JavaScript
Alexander Ivanov, 2019-05-02 11:50:04

How to fix TypeError: Cannot set property 'address' of undefined?

I catch an error - TypeError: Cannot set property 'address' of undefined
I understand the essence of the error, at a certain iteration of the loop the variable is not defined.
In a loop, a variable always has a value, only at the end it doesn't. How to fix?
Tried to catch values ​​with the help of conditions, does not help.

query_region.find({}, function(err,getoverhaulhouselistbyaoguids){                           
                                             var i = 80;
                                             var z = 97;
                                             for(var l = 0; l < i; l++){
                                                 for(n = 0; n < z; n++){
                                                          if(getoverhaulhouselistbyaoguids == undefined){
                                                            console.log('asdsads');
                                                          }

                                                                 const jsonAdressAndCountPeople = [];
            
                                                                jsonAdressAndCountPeople.push( 
                                                                                               getoverhaulhouselistbyaoguids[l]['data'][n].address , 
                                                                                               getoverhaulhouselistbyaoguids[l]['data'][n].totalPpl );
                                                                 
                                                                var language = "ru";
                                                                var city = "Алтайский край";
                                                                var street = getoverhaulhouselistbyaoguids[l]['data'][n].address;

                                                               
                                                                var clearStreet =street.replace(/([а-яa-zё-]+).*?(\s|$)/gi, (r, s) => s.length <= 4 ? '' : r);
                                                                   var clearStreet = clearStreet.replace(",", "");
                                                                   var clearStreet = clearStreet.replace(".", "");
                                                                var format = "jsonv2";                                        
                                                                var cityCode = encodeURIComponent(city);
                                                                var streetCode = encodeURIComponent(clearStreet);
                                                                var get = "https://nominatim.openstreetmap.org/search?q="+streetCode+"&format=json&polygon=1&addressdetails=1";                               
                                                                            axios.get(get)
                                                                          .then(function (response) {
                                                                            console.log(response);
                                                                            res.setHeader('Content-Type', 'application/json');
                                                                            //var data = response;
                                                                            var data = res.end(response.query);
                                                                            var lat = response["data"][0]['lat'];
                                                                            var lon = response["data"][0]['lon'];
                                                                            var display_name = response["data"][0]['display_name'];                           
                                                                            var jsonArr = [];                                                           
                                                                            jsonArr.push({
                                                                                0: lat,
                                                                                1: lon,
                                                                                2: display_name
                                                                            }); 
                                                                           console.log(jsonArr);
                                                                            return res.end('index', { data : data, q :q });
                                                            
                                                                          })
                                                                          .catch(function (error) {
                                                                            console.log('error');
                                                                            console.log(error);
                                                                          });      
                                                 }                       
                                }                        
                                    });                              
                                    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynn "Coffee Man", 2019-05-02
@Lynn

You misunderstand. You do not have the address variable not defined, but some object in which you want to assign the address. In fact, the error message usually contains the filename and line number.
In any case, look for an error in the line of the form
AND find out why your obj is not defined.

K
Karroplan, 2017-04-07
@Karroplan

make more classes in the internal policy of XXX-Video and let telemetry be in priority, and video conferencing in a guaranteed bandwidth, tk. Videoconferencing is easier to survive jitter than telemetry:
class-map match-all telemetry
... whantever ...
!
policy-map XXXX-Video
class telemetry
priority 2000
class Video-any
bandwidth 2000
class class-default
fair-queue
!

F
f0x_m, 2017-04-27
@f0x_m

Something like this. Define separate classes for the required traffic. If there is telephony, then be sure to use priority. it activates LLQ, which is important for telephony. For other classes, cut strips as needed.
class-map match-all REALTIME-DATA
match ip dscp ef
class-map match-any CRITICAL-DATA
match ip dscp cs3 cs6
class-map match-any IPTV
match ip dscp cs4
policy-map OUT-POLICY
class REALTIME-DATA
priority percent 5
class IPTV
bandwidth percent 60
class CRITICAL-DATA
bandwidth percent 20
random-detect dscp-based
class class-default
random-detect dscp-based

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question