How to use object literals In Javascript
JavaScript allows us to create and define the objects using curly braces { } which are called object literals. These objects’ literals have key-value pairs where identifiers or strings are the keys and the value can be of any data type be it object, string, number, etc.
Example: This example shows creating nested objects using object literals.
Javascript
let object = { Company: { name: "w3wiki" , location: "Noida" , Domains: { Courses: [ "DSA Self Paced Course" , "Full Stack Development" , "Devops Boot Camp" , "GATE Prepration" ], Articles: [ `Interview Prepration, Algorithms, Data Structures, Web Development`] } }, } console.log(object); |
Output
{ Company: { name: 'w3wiki', location: 'Noida', Domains: { Courses: [Array], Articles: [Array] } } }
How to Create a Nested Object in JavaScript ?
JavaScript allows us to create objects having the properties of the other objects this process is called as nesting of objects. Nesting helps in handling complex data in a much more structured and organized manner by creating a hierarchical structure.
These are the different methods to create nested objects in JavaScript are as follows:
Table of Content
- Using object literals
- Using square bracket notations
- Using factory function
- Using Object.create() method
- Using object constructor
- Using JavaScript classes