Похожие чаты

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 ответов

19 просмотров

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) { }

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта