Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-del

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-del

Delete (nested) keys from JSON object

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 01 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc