# object-path-set
**Repository Path**: mirrors_skratchdot/object-path-set
## Basic Information
- **Project Name**: object-path-set
- **Description**: set values in javascript objects by specifying a path
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-09-25
- **Last Updated**: 2026-05-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# object-path-set
[](http://badge.fury.io/js/object-path-set)
[](https://travis-ci.org/skratchdot/object-path-set)
[](https://codeclimate.com/github/skratchdot/object-path-set)
[](https://coveralls.io/github/skratchdot/object-path-set?branch=master)
[](https://david-dm.org/skratchdot/object-path-set)
[](https://david-dm.org/skratchdot/object-path-set#info=devDependencies)
[](https://npmjs.org/package/object-path-set)
## Description
set values in javascript objects by specifying a path.
if the path doesn't exist yet, it will be created.
by using this library, you can help prevent the following error from occurring:
```
Cannot set property 'foo' of undefined
```
NOTE: I've re-written / used this function so many different times, I decided to publish it
as a module.
## Getting Started
Install the module with: `npm install --save object-path-set`
```javascript
var setPath = require('object-path-set');
var obj = { foo: { bar: 'baz' } };
obj = setPath(obj, 'foo.bar', 'newValue'); // result: {foo:{bar:'newValue'}}
obj = setPath(obj, 'foo.invalidKey', 'cool'); // result: {foo:{bar:'newValue',invalidKey: 'cool'}}
obj = setPath(obj, 'foo|bar', 'again', '|'); // result: {foo:{bar:'again',invalidKey: 'cool'}}
```
## Links
- [Source Code](https://github.com/skratchdot/object-path-set)
- [Changelog](https://github.com/skratchdot/object-path-set/blob/master/CHANGELOG.md)
- [Live example on Runkit](https://npm.runkit.com/object-path-set)
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
| [
◬](https://www.skratchdot.com/)
[💻](https://github.com/skratchdot/object-path-set/commits?author=skratchdot "Code") [📖](https://github.com/skratchdot/object-path-set/commits?author=skratchdot "Documentation") |
| :---: |
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
## License
Copyright (c) 2014 skratchdot
Licensed under the MIT license.