key-del

Delete (nested) keys from JSON object

npm install key-del
2 downloads in the last day
22 downloads in the last week
51 downloads in the last month

Delete (nested) keys from JSON object

NPM

Assumptions

  • original object shall not be modified
  • modified object is returned as a result of the invocation
  • nested keys shall be deleted as well

Usage

  • takes two parameters (object, and keys to delete)
  • second parameter is a string (for single key), or array (for multiple keys)

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