JS Basic Tutorial
Method |
Description |
Example |
---|---|---|
Modifying Object Properties |
let person = { name: "John", }; person.age = 30 // {name:"John",age:30} delete person.name // {age:30} |
|
Get all keys in the object. |
let person = { name: "John", age : 30 }; Object.keys(person) // ["name", "age"] |
|
Get all values in the object. |
let person = { name: "John", age : 30 }; Object.values(person) // ["John", 30] |
|
Get key-value pairs as an array. |
let person = { name: "John", age : 30 }; Object.entries(person) // [["name", "John"], ["age", 31]] |
|
Copy properties from one object to another. |
let person = { name: "John", age : 30 }; const additionalInfo = { profession: "Engineer" }; const updatedPerson = Object.assign(person, additionalInfo); // {name: "John",age : 30,profession: "Engineer"}; |
|
Prevents modifications (add, delete, or update) |
let person = { name: "John", }; Object.freeze(person); person.age = 30 // error will through |
|
Prevents adding or deleting, but allows updating existing properties. |
let person = { name: "John", }; Object.seal(person); person.name = "Doe" // {name : "Doe"} person.age = 30 // error will through delete person.name // error will through |
Modifying Object Properties
Try it yourself
Get all keys in the object.
Try it yourself
Get all values in the object.
Try it yourself
Get key-value pairs as an array.
Try it yourself
Copy properties from one object to another.
Try it yourself
Prevents modifications (add, delete, or update)
Try it yourself
Prevents adding or deleting, but allows updating existing properties.
Try it yourself