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

Object Methods

The document explains various object methods in JavaScript, including Object.keys(), Object.values(), Object.entries(), Object.assign(), Object.freeze(), and Object.seal(). Each method is described with examples demonstrating its functionality, such as returning property names, values, or key-value pairs, and modifying object properties. Additionally, it highlights the differences between freezing and sealing an object.

Uploaded by

ramp68201
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)
9 views5 pages

Object Methods

The document explains various object methods in JavaScript, including Object.keys(), Object.values(), Object.entries(), Object.assign(), Object.freeze(), and Object.seal(). Each method is described with examples demonstrating its functionality, such as returning property names, values, or key-value pairs, and modifying object properties. Additionally, it highlights the differences between freezing and sealing an object.

Uploaded by

ramp68201
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
You are on page 1/ 5

Lesson:

Object methods
List of content:
Object methods
Types and examples
Object Methods:

Actions on objects are carried out using methods. An object Property that includes a function declaration is
known as an object method.

Types of object methods


Object.keys(
Object.values(
Object.entries(
Object.assign(
Object.freeze(
Object.seal()
Object.keys():

It is a method that returns an array of an object's own property names.


var emp = {

name: 'Alex',

age: 27,

salary:10000

};

var keys = Object.keys(emp);

console.log(keys);
Output:

Object.values():

Object.values() is a method that returns an array of an object's own property values.

Full Stack Web Development


var emp = {

name: 'Alex',

age: 27,

salary:10000

};

var rec = Object.values(emp);

console.log(rec);
Output:

Object.entries()

This method is used to return an array of enumerable property [key, value] pairs of the object passed
as the parameter.
var emp = {

name: 'Alex',

age: 27,

salary:10000

};

console.log(Object.entries(emp)[1]);
Output:

Object.assign():

The values and properties of one or more source objects are copied to a destination object using the
Object.assign() function.

Full Stack Web Development


var emp = {

name: 'Alex',

age: 27,

salary:10000

};

const emp_obj = Object.assign({},emp)

console.log(emp_obj);
Output:

Object.freeze():

An object is frozen using this method.

Changing a frozen object is impossible. It prevents the addition and deletion of properties. Additionally, it
prevents changes to property values from occurring unless an object is involved.
var emp = {

name: 'Alex',

age: 27,

salary:10000

};

Object.freeze(emp);

console.log(Object.isFrozen(emp));
Output:

Object.seal():

It is a method identical to Object.freeze(). You cannot add or remove an object's properties, but you can
edit the value of an existing property.

Full Stack Web Development


var emp = {

name: 'Alex',

age: 27,

salary:10000

};

Object.seal(emp);

console.log(Object.isSealed(emp));
Output:

Full Stack Web Development

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy