<!-- !
Object -->
Object in JavaScript
Definition:
An object in JavaScript is a collection of key-value pairs.
Each key is a property name (or method name), and the co rresponding value can
be any data type, including other objects or functions.
Syntax:
let objectName = {
key1: value1,
key2: value2,
method1: function() {
// Method code
}
};
<!-- ! methods -->
1. `[Link]()`
Definition:
The `[Link]()` method returns an array of a given object's property names
(keys).
Syntax:
[Link](object);
2. `[Link]()`
Definition:
The `[Link]()` method returns an array of a given object's property
values.
Syntax:
[Link](object);
3. `[Link]()`
Definition:
The `[Link]()` method returns an array of key-value pairs (as arrays)
from an object.
Syntax:
[Link](object);
4. `[Link]()`
Definition:
The `[Link]()` method freezes an object, meaning its properties cannot
be added, removed, or modified.
Syntax:
[Link](object);
5. `[Link]()`
Definition:
The `[Link]()` similar to `[Link]()` but here we can modify the
object.
Syntax:
[Link](object);
6. `[Link]()`
Definition:
The `[Link]()` method is opposite of `[Link]()`, it
converts the array to object.
Syntax:
[Link](object);
7. `[Link]()`
Definition:
The `[Link]()` method copies all properties from one or more source
objects to a target object. It returns the modified target object.
Syntax:
[Link](target, ...sources);
8. `[Link]()`
Definition:
The `hasOwnProperty()` method returns a boolean indicating whether the object
has the specified property as its own (not inherited) property.
Syntax:
object_name.hasOwnProperty(property);
// ! how to declare object
let student = {
name:"bheem",
age:10,
isStudent:true,
subjects:['java','js','html','css'],
work: ()=>{ [Link]('hello i am function inside student object')},
address : {
city:"chennai",
pin:785645
}
}
[Link](student)
// ! how to access any element from the object
// by using dot(.)
[Link]([Link])
[Link]([Link])
// by using ["key_name"]
[Link](student["age"])
// ! how to add element in object
[Link] = 9898777777
[Link](student)
// ! how to modify any key value
[Link] = 15
[Link](student)
// ! how to delete element from object
delete [Link]
[Link](student)
// ! how to call any function that is present inside object
[Link]()
// ! Methods Of Object
let obj = {
name:"abc",
age:10,
marks:[45,67,89],
isActor:false
}
// ! 1. [Link](object_name)
let keys = [Link](obj)
[Link](keys)
// ! 2. [Link](object_name)
let values = [Link](obj)
[Link](values)
// ! 3 . [Link](object_name)
let entries = [Link](obj);
[Link](entries)
// ! 4. [Link]()
let obj2 = [Link](entries)
[Link](obj2)
// ! 5. [Link](object_name)
// [Link]("before freeze")
// [Link](obj)
// [Link](obj)
// [Link] = 23455677 // we can't add
// [Link] = 20 // we can't modify
// delete [Link] // we can't delete
// [Link]('after freeze')
// [Link](obj)
// ! 6. [Link]()
// [Link]([Link](obj))
// ! 7 . [Link](object_name)
// [Link](obj)
// [Link]('before seal')
// [Link](obj)
// [Link]('after seal')
// [Link] = 9812345678 // we can't add
// delete [Link] // we can't delete
// [Link]= 20 // yes, we can modify
// [Link](obj)
// ! 8. [Link](object_name)
// [Link]([Link](obj))
// ! 9. object_name.hasOwnProperty('key_name')
[Link]([Link]("subject")) //false
[Link]([Link]("age")) // true
let a = 'no 1 in tamil nadu'
'no 2 in tamil nadu'
[Link]('5' - 5) //0
if(true)
{
[Link]('hhhhhh')
}
[Link](a)
// ! 10. [Link]()
let obj10 ={
name:"sachin"
}
let obj20 ={
phno:2341234567
}
let combinedObj = [Link]({},obj10, obj20)
[Link](combinedObj)