Can't acess the dictionary! | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

Can't acess the dictionary!

Here's my code, see the JS and HTML. Run the code, and type, in the input, "Hydrogen". It's giving errors as can't read property of null. Why? In spck.io, it says undefined. Is there any alternative of what I am doing? https://code.sololearn.com/Wl4S9Y407GyL/?ref=app

24th Apr 2023, 2:26 PM
Parth
Parth - avatar
3 Antworten
+ 8
https://code.sololearn.com/WWwVf7A229od/?ref=app Parth This edited code👆🏻 works...... I am not sure about this but maybe When we try to use input.value as object names it will consider it as undefined Because it takes input.value as string For example: "dict" and dict are different (here dict is a name of the object eg: var dict ={ name : "value" } ) you need to explicitly defined the object names to access its particular element
24th Apr 2023, 3:47 PM
Suparna Das
Suparna Das - avatar
+ 5
Parth Javascript doesn't have dictionaries, {} curly bracket with pair {key: values} samulat objects in Javascript. Javascript allows as to access its value with key but you are trying to access the values from a string with object keys that Will output undefined. Because Input tag always returns an string and string has index but not key for accessing.
24th Apr 2023, 3:58 PM
Yasin Rahnaward
Yasin Rahnaward - avatar
0
Suparna Das , Yasin Rahnaward Okk I get it. But isn't there any other way of doing it. Because I want to make objects of 118 elements. But then, making the searchEle func for every 118 elements will be very frustrating!
26th Apr 2023, 1:41 PM
Parth
Parth - avatar