简体   繁体   English

分配键时如何处理错误:object 中的值?

[英]How can i handle error when assign key: value in object?

Im using web API to create some aplication displaying data about countries and teritories.我使用 web API 创建一些应用程序来显示有关国家和地区的数据。 I have object with several properties for eg.我有 object 有几个属性,例如。

country {...
         currencies: Object.values(country.currencies)
         .map((currency) => currency.name)
         .join(", "),
          ...}

For countries having no such things like Antarctica ive got and error "Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Function.values ()" and entire datail page not displaying.对于没有像南极洲这样的东西的国家,我得到了错误“Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Function. The question is how to handle this error, how to make exeption for those few countries having no currency.问题是如何处理这个错误,如何对那些没有货币的少数国家进行豁免。 Maybe some "if" statement or alternative value for "currencies"?也许一些“if”语句或“货币”的替代值?

Im downloading data from this API - "https://restcountries.com/v3.1/all", when im not using "Object.value", detailed page i create load but i got "currencies: [object Object]" entry for every single country.我从这个 API 下载数据 - “https://restcountries.com/v3.1/all”,当我不使用“Object.value”时,我创建了详细页面,但我得到了“货币:[object Object]”条目对于每一个国家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM