Prev Demo
Object When The Property Name Is Number
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Object When the property name is number.</h1> <script> var rankList = { 50: "Students", 5: "Toppers" }; console.log(rankList.50) // This is an Error console.log(rankList["50"]) //This is how we need to access the value of the property </script> <p><strong>Note:</strong> Observe script code in code box, console.log(rankList.50) will through an error, that can be seen in the debugger window.<br> console.log(rankList["50"]) is the correct way to access the value of the property, when the property name is number. </p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output