+ 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
3 Respostas
+ 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 />`"));
+ 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.
0
Thank you for your answers