Skip to content

Instantly share code, notes, and snippets.

@joelnet
Created March 1, 2019 07:27
Show Gist options
  • Select an option

  • Save joelnet/d8ef09c15d83485cf684e98ca1e55735 to your computer and use it in GitHub Desktop.

Select an option

Save joelnet/d8ef09c15d83485cf684e98ca1e55735 to your computer and use it in GitHub Desktop.

Revisions

  1. joelnet created this gist Mar 1, 2019.
    15 changes: 15 additions & 0 deletions rest-spread-tricks-05.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const user1 = {
    id: 100,
    name: 'Howard Moon',
    password: 'Password!'
    }
    const removeProperty = prop => ({ [prop]: _, ...rest }) => rest
    // ---- ------
    // \ /
    // dynamic destructuring

    const removePassword = removeProperty('password')
    const removeId = removeProperty('id')

    removePassword(user1) //=> { id: 100, name: 'Howard Moon' }
    removeId(user1) //=> { name: 'Howard Moon', password: 'Password!' }