Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Remove unwanted properties from a JavaScript with ES6 spread operator


    In this lesson we are going to learn how to remove unwanted properties from a JavaScript object following an example of an object containing sensitive data (such as password and bankBalance) and removing this kind of data from it.

    To achieve that we are going to use two ES6 features: destructuring an object and the spread operator.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: In this example we have an object containing some sensitive data about a user. We have a name, a surname, a password, which is stored in plain text, the user ID, and the bank balance.

    What we'd like to do is create a user data object which is going to contain all the user data but with the exception of password and bank balance, because this is not something that we would like to make public.

    To do that, destructure the sensitive data object as follows. We're going to do const password, bank balance, and we're going to spread the rest of this sensitive data to a new one that we're going to call user data. It's going to be equal to sensitive data.

    This way we get a brand new JavaScript object which contains everything that the sensitive data had but without the password and bank balance because those properties are destructured separately.