Skip to content

Instantly share code, notes, and snippets.

@jonaswide
Last active January 24, 2018 12:40
Show Gist options
  • Save jonaswide/70a945a8e7240d0537a23f241fb1a64f to your computer and use it in GitHub Desktop.
Save jonaswide/70a945a8e7240d0537a23f241fb1a64f to your computer and use it in GitHub Desktop.

Revisions

  1. jonaswide revised this gist Jan 24, 2018. No changes.
  2. jonaswide revised this gist Jan 24, 2018. No changes.
  3. jonaswide created this gist Jan 24, 2018.
    5 changes: 5 additions & 0 deletions add-prop-to-obj.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    export const addPropToObj = key => obj => val => ({ ...obj, [key]: val })

    // Example
    const firstObj = { a: 1, b: 2, c: 3 }
    addPropToObj("d", firstObj, 4) // { a: 1, b: 2, c: 3, d: 4 }