पाठ 17 / 40
ऑब्जेक्ट लिटरल और प्रॉपर्टीज़
Literals से objects बनाएँ, dot व bracket notation से properties पढ़ें और keys जोड़ें या हटाएँ।
ऑब्जेक्ट बनाना
प्रॉपर्टीज़ को dot notation या bracket notation से पढ़ा जा सकता है।
const person = {
name: "Ada",
age: 36,
isActive: true,
};
console.log(person.name); // dot notation
console.log(person["age"]); // bracket notationजोड़ना और हटाना
नई key को असाइन करने से प्रॉपर्टी जुड़ जाती है; delete से इसे पूरी तरह हटाया जा सकता है।
person.city = "London";
delete person.isActive;
console.log(person);Dot बनाम bracket
जब key डायनामिक हो या वैध identifier न हो तब bracket notation उपयोग करें: person["first-name"]।