1.3.0 • Published 6 years ago

key-del v1.3.0

Weekly downloads
25,665
License
MIT
Repository
github
Last release
6 years ago

Delete (nested) keys from JSON object

Build Status Dependency Status

NPM

Assumptions

  • original object shall not be modified by default
  • modified object is returned
  • 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

Usage

var deleteKey = require('key-del')
var objWithoutOneAttribute = deleteKey({one: 1, two: 2}, 'one')

Examples

var deleteKey = require('key-del')

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

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

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

// Delete nested key by full path
var objectToDeleteKeyFrom = { one: 1, two: 2, nested: {two: 2, three: 3}}
var keyToDelete = 'nested.two'
var result = delKey(objectToDeleteKeyFrom, keyToDelete)
console.log(result)
// { one: 1, two: 2, nested: {three: 3}}

Options

To delete attribue from the original object, set copy parameter to false (its true by default)

deleteKey(originalObject, 'one', {copy: false})
console.log(originalObject)
// original object is modified
// { one: 1, two: 2, three: { nestedOne: 3, nestedTwo: 4 } }

Licence

The MIT License (MIT)

Copyright (c) 2015, Andrei Karpushonak aka @miktam

1.3.0

6 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago