Is it possible to check for null inline in javascript?

前端 未结 7 2307
孤街浪徒
孤街浪徒 2020-12-15 18:27

I have a function which parses the address components of the Google Maps API JSON and then returns the city / locality / route name.

The getAddre

7条回答
  •  旧时难觅i
    2020-12-15 19:11

    let component = getAddressComponent(addressComponents, 'route');
    let route = component ? component : null
    

    you can use the ? operator to check the value is true or false then set the value in javascript null will be false

提交回复
热议问题