//Revision Lecture 8: 2 Oct 2022
//Topic 6: //* Operations with Object *//
let info = {
firstName: 'Virat',
lastName: 'Kohli'
}
//1) retrieve property & value from object
//dot notation
console.log(info.firstName)
console.log(info.lastName)
//bracket notation
console.log(info['firstName'])
console.log(info['lastName'])
//2) add property to object
//dot notation
info.age = 32
console.log(info)
//bracket notation
info['city'] = 'Delhi'
console.log(info)
//3) update property of object
//dot notation
info.firstName = 'Virendra'
console.log(info)
//bracket notation
info['lastName'] = 'Sehwag'
console.log(info)
//4) delete property of object
//dot notation
delete info.city
console.log(info)
//bracket notation
delete info['age']
console.log(info)
//Example 2:
info2 = {
CarName: 'Scorpio',
Color: 'White'
}
// retrieve
console.log(info2.Color)
console.log(info2.CarName)
console.log(info2['CarName'])
console.log(info2['Color'])
// add
info2.Number = 2030
console.log(info2)
info2['State'] = 'Maharashtra'
console.log(info2)
// update
info2.Number = 5060
console.log(info2)
info2['State'] = 'UP'
console.log(info2)
// delete
delete info2.CarName
console.log(info2)
delete info2['Color']
console.log(info2)
टिप्पण्या
टिप्पणी पोस्ट करा
आपल्या प्रतिक्रियेबद्दल धन्यवाद ! आम्ही लवकरात लवकर प्रतिक्रियेला उत्तर देण्याचा प्रयत्न करू