+ 1

Completely lost with this objects. Why do i get undefined - maybe the issue is hidden under the eval method.

Testing the objects introduced by ES6-JavaScript https://code.sololearn.com/WjveUmz5J4mL/?ref=app

23rd Mar 2020, 2:15 PM
爱人么你
爱人么你 - avatar
3 Respuestas
+ 1
You get undefined because data property does not exists in goblin object You can do this and it will work: document.write(eval("`${data}-of-${gobMobs[goblinInd].name}-${gobMobs[goblinInd]."+data+"}<hr />`"));
23rd Mar 2020, 4:07 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 1
document.write(`${data}-of-${gobMobs[goblinInd].name}-${eval("gobMobs[goblinInd]." + data)}<hr />`); You were kind of right in that the issue was with eval(). The issue was that the code was checking for gobMobs[goblinInd].'name' rather than gobMobs[goblinInd].name and so on.
23rd Mar 2020, 4:09 PM
Russ
Russ - avatar
0
Thank you for your answers
24th Mar 2020, 10:41 AM
爱人么你
爱人么你 - avatar