How To: Delete property from an Object using spread operator

Learn These 6 Figure Scraping Techniques As A Side Hustle

Access secret data points from SaaS websites and much more.

ā†’ 6 Figure Scraping Guide ā†

Use this data for your own startup or sell it to those that need it.

No spam, just Javascript, web3 and indie hacking!


    We won’t send you spam. Unsubscribe at any time.

    Everyday there’s something new to learn with Javascript.

    I was trying to manipulate an object and remove one of the properties but I didn’t want to mutate the original object. I knew there must be a cleaner way than to use the delete operator

    That got me thinking about the spread operator and it turns out you can remove properties while spreading the rest of the values into a new object.

    let user = {
        name: 'Calvin',
        age: 200,
        country: 'Spain',
        food: 'Pizza'
    const {name, ...restOfUser} = user
    // { age: 200, country: 'Spain', food: 'Pizza' }
    // Calvin

    I now get the removed property value and also a new object with all the rest of the values.