[Go to site: main page, start]

0% found this document useful (0 votes)
10 views5 pages

JavaScript Objects: Comprehensive Guide

This document provides a comprehensive guide on JavaScript objects, covering their definition, creation methods, property access, and manipulation techniques. It also discusses object methods, the 'this' keyword, nested objects, and various ways to search and compare objects. Additionally, it includes advanced topics such as object destructuring, JSON handling, and the use of Object.freeze() and Object.seal().
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

JavaScript Objects: Comprehensive Guide

This document provides a comprehensive guide on JavaScript objects, covering their definition, creation methods, property access, and manipulation techniques. It also discusses object methods, the 'this' keyword, nested objects, and various ways to search and compare objects. Additionally, it includes advanced topics such as object destructuring, JSON handling, and the use of Object.freeze() and Object.seal().
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Objects - Full Guide

1. What is an Object?
An object in JavaScript is a structure to store key-value pairs.

let person = {
name: "Ali",
age: 22,
city: "Anantnag"
};

2. Creating an Object
a. Object Literal

let car = {
brand: "Honda",
model: "Civic",
year: 2020
};

b. new Object()

let user = new Object();


[Link] = "Sara";

c. Constructor Function

function Animal(name, type) {


[Link] = name;
[Link] = type;
}
let dog = new Animal("Tommy", "Dog");

3. Accessing Properties

[Link];
car["model"];
4. Adding / Updating / Deleting Properties

[Link] = "red";
[Link] = 2021;
delete [Link];

5. Object Methods

let student = {
name: "Ali",
greet: function () {
[Link]("Hello, " + [Link]);
}
};
[Link]();

6. The 'this' Keyword


this refers to the current object inside methods.

7. Nested Objects

let company = {
name: "TechSoft",
address: {
city: "Delhi",
pin: 110001
}
};

8. Looping Through Objects

for (let key in book) {


[Link](key + ": " + book[key]);
}
9. [Link](), [Link](), [Link]()

[Link](obj);
[Link](obj);
[Link](obj);

10. Object Destructuring

let { name, age } = user;

11. [Link]() and [Link]()

[Link](obj);
[Link](obj);

12. Spread and Rest

let a = { x: 1 };
let b = { ...a, y: 2 };

let { x, ...rest } = { x: 1, y: 2, z: 3 };

13. Object Comparison

let a = { name: "Ali" };


let b = { name: "Ali" };
[Link](a === b); // false

14. JSON and Objects

let json = [Link](obj);


let obj = [Link](json);

15. Searching in Objects


a. 'in' Operator

"age" in person;
b. hasOwnProperty()

[Link]("city");

c. [Link]().includes()

[Link](person).includes("Anantnag");

d. .find()

[Link](function(student) {
return [Link] === "Ali";
});

e. .filter()

[Link](function(student) {
return [Link] === "A";
});

f. Loop

for (let i = 0; i < [Link]; i++) {


if (students[i].name === "Ali") {
[Link](students[i]);
}
}

g. Case-insensitive Search

[Link](function(student) {
return [Link]() === "ali";
});

16. Summary Table


Method Checks For Works On Returns
key in object Key Object true/false
hasOwnProperty() Own Key Object true/false
[Link]().includes() Value Object true/false
.find() First Match Array Object or undefined
.filter() All Matches Array Array
for loop Custom Logic Any Custom

You might also like