Skip to content

gearcase/object-unset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-unset

Removes the property at path of object.

MIT License

build:? coverage:?

Install

$ npm install --save object-unset 

Usage

For more use-cases see the tests

var unset = require('object-unset');

unset({ a: { b: { c: 7 } } }, 'a');
// => {}

unset({ a: [{ b: { c: 7 } }] }, 'a[0]');
// => {a: [] }

unset({ a: [{ b: { c: 7 } }] }, 'a.0');
// => {a: [] }

unset({ a: { b: { c: 7 } } }, 'a.b.c');
// => { a: { b: {} } }

{ a: [{ b: { c: 7 } }] }, 'a[0].b.c');
// => { a: [{ b: {} }] }

unset({ a: [{ b: { c: 7 } }] }, 'a[0].d.c');
// => { a: [{ b: { c: 7 } }] }

unset(null, 'a.b.c');
// => null

unset({ a: 1 }, 'a.b.c.d');
// => { a: 1 }

Related

  • object-set - Sets the value at path of object.
  • object-at - Get object's property according to the path.
  • object-has - Checks if path is a direct property of object.
  • to-path - Converts string to a property path array.

Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please create an issue.

About

Removes the property at path of object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published