Understanding Object Method In Javascript.

In JavaScript, an object is a containers for named values called properties. E.g. a generator. All generator have the same properties, but the property values differ from generator to generator. All generators have the same method, but the methods are performed at different times while a variable is an address or a location memory where you can store any value. E.g. a box in which you can store different items at different times. Object are variable too but object can contain many values. Eg.

Const generator = {type:’’Fireman’’, model: ‘’310'’; color: ‘’red’’};

The value are written as name:value pairs (name and value separated by a colon).

4 Types of JavaScript method

1. Object.Keys() :- it create an array containing the keys of an object. E.g.

Const num = {

One : 1,

Two : 2,

Three: 3,

}

Console.log(object.keys(num)); / / [‘one’, ‘two’, ‘three’ ]

2. Object.values() :- it create an array containing the values of an object. E.g.

Const num = {

One : 1,

Two : 2,

Three: 3,

}

Console.log(object.keys(num)); / / [1,2,3]

3. Object.enteries():- it’s used to create a nested array of the key/value pairs of an object. Eg.

Const num = {

One : 1,

Two : 2,

Three: 3,

}

Console.log(object.entries(num));

/ / Expected output :

// [ [‘one’, 1], [‘two’, 2], [‘three’ 3] ]

4. Object.Seal():- it prevent new properties from being added to an object, but allows the modification of existing properties.

Const user = {

Username: ‘something’,

Password: ‘vmfmbdsmckjrkm’

};

// seal the object

Const newuser = object.seal(user);

newUser.password = ‘************’

newUser.active = true;

console.log(newUser);

*/ Expected output

{username: ‘something’, password: ‘*******’}

Thanks for your time, kindle like and share to assist someone.

Author: Abel K. Kingsley.

Special thanks: PearlxTech Concept and CodeLab By Skill Hub.