xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to create JavaScript Object
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Declare JavaScript Object</title> <!--Script tag is added to write JavaScript code inside it--> <script> //Create an object by using a list of key-value pairs enclosed in curly braces {}. var person = { firstName:"John", lastName:"Smith", age : 25 }; // To access object property use dot (.) after object name followed by the property name var objFirstName = person.firstName; // or use square brackets [] with the property name as a string after object name var objLastName = person['lastName']; function myFunction() { // backticks `` is used for the template string document.getElementById("myObject").innerHTML = `${objFirstName} ${objLastName} is ${person.age} years old.`; } </script> </head> <body> <h1>How to Create JavaScript Object?</h1> <button onclick="myFunction()">Click here to see result</button> <p id="myObject"></p> </body> </html>