Understanding Objects in JavaScript .
Objects :-
Objects are pre defined data structure in JavaScript which is used to store the in the form of as a collection of key-value pair & methods in JavaScript . It is fundamental for storing data of real world entities .
The most common way to create an Object .
const object={
name:"Chirag",
age:18,
favSport:"Cricket"
greet:()=>{
console.log("${this.name} loves to play ${this.favSport}")
}
}
Accessing Properties : We can access its properties easily using object.name or object["name"] .
Editing : Also we can edit it's properties using the object.name="Chirag Purohit" .
Deleting : We also delete it properties using the delete object.name
Applying Loop Over the Object to access each property
const user={ name:"dalla", age:40, profession:"Math's teacher" } for(let key in user){ console.log(`${key}:${user[key]} `); }
Comments
Join the discussionNo comments yet. Be the first to comment.
