+ 1

How can I get firstName in this code

let grammarcorrah = { firstName: 'Grammar', lastName: 'Corrah' } function checkFunc() { for (let element in grammarcorrah) { document.getElementById("demo1").innerHTML = element; } } https://code.sololearn.com/WduGP0uCQux1/?ref=app

26th Aug 2022, 7:10 PM
Steve Nova
Steve Nova - avatar
3 Respuestas
+ 3
You are replacing firstName with lastName by loop. Just use like this: let grammarcorrah = { firstName: 'Grammar', lastName: 'Corrah' } function checkFunc() { document.getElementById("demo1").innerHTML = grammarcorrah.firstName; document.getElementById("demo2").innerHTML = grammarcorrah.lastName; } //document.getElementById("demo1").innerHTML = grammarcorrah['firstName']; // index method
26th Aug 2022, 7:57 PM
Jayakrishna 🇮🇳
+ 2
grammercorrah.firstName grammercorrah['firstName']
26th Aug 2022, 7:50 PM
MATOVU CALEB
MATOVU CALEB - avatar
+ 1
Thank you my _black belt coders_ for your help
27th Aug 2022, 8:57 AM
Steve Nova
Steve Nova - avatar