key-del

Delete nested keys from Javascript object, JSON

npm install key-del
1 downloads in the last day
25 downloads in the last week
43 downloads in the last month

Delete keys from Javascript object

NPM

Assumptions

  • takes two parameters (object, and keys to delete)
  • second parameter (keys to delete) could be string for single key, or array of strings (for multiple keys)
  • original object shall not be modified
  • modified object is returned as a result of the invocation
  • nested keys shall be deleted as well

Installation

npm install key-del

Examples

var deleteKey = require('key-del')

var originalObject = {
    one: 1,
    two: 2,
    three: {
      nestedOne: 3,
      nestedTwo: 4
    }
}

console.log(originalObject) // { one: 1, two: 2, three: { nestedOne: 3, nestedTwo: 4 } }

var result = deleteKey(originalObject, ['one', 'nestedOne'])

console.log(result) // {two: 2, three: {nestedTwo: 4}}
npm loves you