Похожие чаты

Hi everyone I am using an api from the public-apis from

github and it basically gives information about the country that we request
Now I have encountered a problem and I don't really know how to figure it out
I want to create a card based on the information on the api but I want to do it dynamically and not hardcoding the information inside of the api

This is the structure of the api:
{
other properties,
languages: { eng: "English" },
other properties
}

When I change the country, the eng object inside of the languages object also changes, the example above is for the USA while when I try to get the information for Portugal, I get this:

{
other properties,
languages: { por: "Portugese" },
other properties
}

So the name of the object inside of the languages object changes

How can I select that object inside of languages dynamically? I mean surely I can select them like this:

obj.languages.eng for USA and obj.languages.por for Portugal, but how can I select it dynamically and not hardcoding it myself?

3 ответов

14 просмотров

If there’s only a single dynamic property in the object, you can extract it like so: const obj = { dynamicKey: “value” }; console.log(Object.values(obj)[0]); // value

Mehrshad- Автор вопроса
Shayan
If there’s only a single dynamic property in the o...

Yeah that's it exactly Thanks But I think it will make the code a little bit messy espescially if there are multiple properties like this that we need to look for

Use enums

Похожие вопросы

Обсуждают сегодня

Hey everyone! I won’t focus too much on what this person said (it’s clear they don’t understand the scope of what TF and TELOSX are achieving), but I’ll put it simply for thos...
Ana Ojeda
3
Hi did any of you experience a file error when download hex file for Windows?
Valya
17
как правильно удалить сддм? прописал в etc/portage.use/plasma-meta -sddm , но при обновлении юзов мне предлагает поставить lightdm (ещё лучше 😡), добавил туда - display-manage...
REDis
25
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
Коллеги, я тут для личных нужд пошел ставить MQTT сервер, пощупал mosquitto, но ужаснулся отсутствию такой банальности, как HTTP API для посмотреть список топиков. А тут что,...
Maksim Lapshin
14
Please I want to ask if my stake is 24% complete, what penalty will I pay if I end the stake?
Crypto Advocate
12
Also, scrolling at the history here, I see there was alot of hate towards kaspa.. is it still the case after they proved the history of the chain?
Gad Levy | AnyLog
11
Could the new Norse labs apps have just been called "VPN" instead of DVPN?
HDGVII
14
How will they work it out?
Max
14
Карта сайта