Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

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

Autoplay

    Remove unwanted properties from a JavaScript with ES6 spread operator

    Tomasz ŁakomyTomasz Łakomy
    javascriptJavaScript

    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.

    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    Instructor: 00:00 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.

    00:10 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.

    00:21 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.

    00:38 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.

    Discuss

    Discuss