Objects & Methods
JavaScript File
// Objects & Methods
document.writeln("
Object Object & Methods
");
let products = {
id: 101,
name: "Laptop",
price: 45000
};
document.writeln("Accessing Objects
");
document.writeln("Object id : ",products.id, "
");
document.writeln("Object Name : ",products.name, "
");
document.writeln("Object Price : ",products.price, "
");
document.writeln("Object id : ", products["id"]);
document.writeln("
");
// Iterating , Objects using for in Method
document.writeln("Iterating Object Using For IN for Objects :
");
for (const i in products) {
document.writeln(products[i]);
}
document.writeln("
");
// Changing Objects values
let books = {
id: 102,
name: "Atomic Habbits",
author: "Martin Arule"
};
document.writeln("Accesing Object Values: ",books.id, books.name, books.author);
// changing objects values
books["author"] = "Akshay Gohrava";
document.writeln("
Changing Object Values: ",books.id, books.name, books.author);
document.writeln("
");
const school = {
id: 103,
name: "SIWS SCHOOL",
location: "Wadala West",
detail: function () {
document.writeln(this.id, this.name, this.location);
}
}
document.writeln(school.detail());
JavaScript Output :