Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Object Properties</h1> <h2>Accessing a Property with an Expression</h2> <p id="demo"></p> <script> const person = { firstName: "John", lastName : "Doe", age : 50 }; let x = "firstName"; let y = "age"; document.getElementById("demo").innerHTML = person[x] + " is " + person[y] + " years old."; </script> </body> </html>