Похожие чаты

Why I am getting cannot read property byId of undefined

?

code:

const temp = this.props.app && this.props.app.byId && Object.keys(this.props.app.byId)[0] ? Object.keys(this.props.app.byId)[0] : undefined;

structure of app:

app: {
byId: {
url1: {
name: 'xyz',
address: "Text"
},
url2: {
name: 'xyz',
address: "Text"
}
}
}

23 ответов

24 просмотра

byid is object not array lel

Adi- Автор вопроса

I want temp to have value url1 so thats why I have used Object.keys(this.props.app.byId)[0]

Adi- Автор вопроса
K P
byid is object not array lel

so how can I fix this issue?

Adi- Автор вопроса
K P
byid is object not array lel

Object.keys(this.props.app.byId)[0] is this wrong?

Adi- Автор вопроса
K P
byid is object not array lel

any idea what I have done wrong?

Adi
any idea what I have done wrong?

which property do you want to read?

Adi- Автор вопроса

this.props.app?.byId?.url1 ?? default-value

Adi- Автор вопроса
Adi
what is default value

Whatever you want. It was just a placeholder

Adi- Автор вопроса
Darvesh 🍀
Whatever you want. It was just a placeholder

but I don't know the content inside byId it can be url1 or url2 or anything so I just want to extract first key and set it to variable how can I do that case?

Adi
what is default value

Important: It will work only on NodeJS version > 14.5

Adi- Автор вопроса
Adi- Автор вопроса

let me explain problem url1 and url2 will not be there initially so byId is empty object now once that object is populated I want to set 1st key which is inside byId to a variable

who even designs such API ? like you are trying to access [0]th property and object keys are interchangeable

K P
byid is object not array lel

Object.keys returns array

Edwing123
For the new features ?

Nullish Coalescing and Optional Chaining

Edwing123
Object.keys returns array

No I meant he wanted to access [0] object key order can vary He wouldn't get what he is expecting

Adi- Автор вопроса
K P
who even designs such API ? like you are trying...

no idea backend dev's did that I actually solved the problem by doing this: if(this.props.app && this.props.app.byId && Object.keys(this.props.byId).length > 0) { }

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта