语句后函数仍在执行

时间:2019-03-09 15:00:48

标签: javascript arrays node.js json if-statement

我正在运行一个IF语句,以检查JSON响应是否为空,以执行下一个功能,但是要同时执行这两个功能。以下是JSON响应的示例,该示例在“ count_business”中具有3个对象,下面是我的函数示例。我正在运行.length <1,但似乎没有检查。

JSON

{
    "count_business": 3,
    "business": [
        {
            "id": "Business.3b725ab1-1eeb-4f11-bb41-0a97cdd5475a",
            "name": "Dogwood Valley Press LLC",
            "industry": [
                "Sporting Goods, Hobby, Musical Instrument, and Book Stores"
            ],
            "found_at_address": {
                "id": "Location.86fc8e6b-6dfb-446d-9488-aae59fea6eb2",
                "location_type": "Address",
                "street_line_1": "1604 Lincoln Ln",
                "street_line_2": null,
                "city": "Rolla",
                "postal_code": "65401",
                "zip4": "2614",
                "state_code": "MO",
                "country_code": "US",
                "lat_long": {
                    "latitude": 37.956933,
                    "longitude": -91.743859,
                    "accuracy": "RoofTop"
                },
                "is_active": true,
                "delivery_point": "SingleUnit",
                "link_to_business_start_date": "2016-06-12",
                "link_to_business_end_date": null
            },

我的if语句

if(res.data.count_business < 1){
                    fetchGooglePlace(data)

                  }else{
                    console.log(chalk.white('RUNNING WHITEPAGES'));
                      for(let i =0; i < res.data.business.length; i++ ){

                          console.log(res.data.business[i].name);
                          console.log(res.data.business[i].found_at_address.street_line_1);

                          /*Second loop to fetch phone numbers from array in whitePages JSON */
                          for (let x = 0; x < res.data.business[i].phones.length; x++) {
                              console.log(res.data.business[i].phones[x].phone_number);
                              console.log('          ');

                          }
                      }
                  }
                })

执行该应用程序后,它将运行whitePages API以及fetchGooglePlace函数。

0 个答案:

没有答案