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.
We didn't get a full example but I assume you have something like this. This might explain how to access these values
const data = [
{
country: "United States",
currencies: {
usd: {
name: "US Dollar",
symbol: "$",
},
},
},
{
country: "England",
currencies: {
usd: {
name: "Sterling Pound",
symbol: "£",
},
},
},
{
country: "Germany",
currencies: {
usd: {
name: "Euro",
symbol: "€",
},
},
},
];
First you need to get property you're trying to destructure, let's say the country you're trying to access is the US.
const selectedCountryData = data.find((val) => val.country === "United States");
And then simply extract values by destructuring
const { currencies: { usd:{ name, symbol } } } = selectedCountryData;