JavaScript 嵌套对象数据访问
我用来访问数据的代码在此处输入图像描述该图片包含来自国家/地区休息 API 的国家/地区数据 货币: 美元: 名称:“美元” 符号:“$”
在这种情况下,关键字 USD 对于每个国家/地区都是不同的,在这种情况下如何通过currency 属性访问该 USD 及其内部属性(名称、符号)。 让currency = { usd: { name: ' ', symbol: ' ' } }; 我用这一行来声明变量,但这一行将更新所有国家的美元。
code I'm using to access dataenter image description herethe picture includes country data from country rest API
currencies:
USD:
name: "United States dollar"
symbol: "$"
In this situation, the keyword USD is different for each country, in that case how to access that USD and properties inside it(name, symbol) through currencies property.
let currencies = { usd: { name: ' ', symbol: ' ' } };
I used this line to declare variable but this line will update usd for all the countries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们没有得到完整的示例,但我假设您有类似的示例。这可能解释了如何访问这些值。
首先,您需要获取您要尝试解构的财产,假设您要访问的国家是美国。
然后通过解构简单地提取值
We didn't get a full example but I assume you have something like this. This might explain how to access these values
First you need to get property you're trying to destructure, let's say the country you're trying to access is the US.
And then simply extract values by destructuring
兄弟,如果您
需要将 Objtect 转换为数组
,那么
如果你想要名称的值,你可以使用
bro if you have
need convert Objtect to an array
then
if you want the value of name you can use