𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗢𝗯𝗷𝗲𝗰𝘁𝘀 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
Objects store data in key-value pairs. You need to know how to create and manage them.
How to create objects:
Object Literals This is the fastest way. let user = { name: "Ezhil", age: 23 };
Object Constructor You use the new keyword here. let user = new Object(); user.name = "Ezhil"; user.age = 23;
Basic operations:
Access properties Use dot notation. console.log(user.name);
Update properties Change the value directly. user.age = 24;
Add properties Assign a value to a new key. user.job = "Developer";
Remove properties Use the delete keyword. delete user.job;
Merge objects Use the spread operator to combine two objects. const merged = { ...obj1, ...obj2 }; You also use Object.assign() to merge data.
Check object length Use Object.keys() to count properties. const length = Object.keys(user).length;
Master these basics to build better applications.
Source: https://www.geeksforgeeks.org/javascript/objects-in-javascript/ Full post: https://dev.to/ezhil_abinayak_e38eec8fb/object-in-js-5048