Redeem Now
Read More
Read now
Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    Javascript Object methods

    Hey, do you know javascript has some Object methods and you can manipulate your object by using that. We will look into such methods in this blog.

    Before starting, let’s observe master obj (Object) closely

    Please see below result

    As you can see above, some methods are listed like assign, create, freeze, etc so we will look into some of the methods in this blog.


    This method is used to create new object by using an existing object

    Syntax: Object.create(propertiesObject);

    let’s see another example of create()

    you can check call() method here


    it is used to copy one or more source objects into target object.

    Syntax: Object.assign(targetObject, ..sourceObjects);

    what happens if target and source objects have the same properties


    You can define an object property by Object.defineProperty()

    Syntax: Object.defineProperty(obj, property, descriptor);

    Let’s see an example

    value: what will be the value of your property

    writable: default it is false which can not be changed, if set true then you can change property

    enumerable: if true then it will display during enumeration

    configurable: default it is false, if true then you can not delete this property

    Set/Get: if using getter and setter then you can not use other keys like writable, enumerable, etc

    You can check getter/setter here


    if you want to add multiple properties then you can use it

    Syntax: Object.defineProperties(obj, properties);

    as you can see in the upper example, I have added three properties similar to Object.defineProperty() example


    It is used for enumerable keys of an object. You will understand the ‘enumerable’ key here which was used under Object.defineProperty ();

    Syntax: Object.keys(obj)

    let’s see now by removing enumerable key for firstName property and see the following code

    In the upper example, firstName property will not get resulted because enumerable is false for firstName property


    It is used for getting all enumerable property values of my object not keys

    Syntax: Object.values(obj)


    Freeze method allows us to prevent add/edit/delete new or existing property. If trying to add/edit/delete in strict mode then it will generate errors.

    syntax: Object.freeze(obj)

    if you will run upper code, then you will get result ‘john’ not ‘webkul’ due to frozen


    For checking any object is frozen or not

    Syntax: Object.isFrozen(obj)


    seal method allows us to prevent add/edit/delete the new or existing property but any existing property can be changed if it is writable. If trying to add/edit/delete any new or existing property in strict mode then it will generate errors except edit in writable case.

    syntax: Object.seal(obj)


    For checking any object is sealed or not

    syntax: Object.isSealed(obj)


    this method has following features

    prevents to add new or existing property

    edit existing property only if writable

    delete existing property if configurable

    syntax: Object.preventExtensions(obj)

    In the upper example, if you will try to delete ‘lastName’ then you will get an error


    For checking any object is extensible or not

    syntax: Object.isExtensible(obj)


    For checking any object’s property

    syntax: obj.hasOwnProperty(propertyName)

    That’s it in this blog. I hope this blog was useful to you. Please ask if you have any queries in the comment section.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again