+ 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
3 Réponses
+ 13
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
+ 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.
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!