This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(removeProperty): add function removeProperty with test (#197)
- Loading branch information
jedilancey
authored and
Kent C. Dodds
committed
Oct 8, 2018
1 parent
5af53e3
commit 0f94be7
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default removeProperty | ||
|
||
/** | ||
* Original Source: https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object | ||
* | ||
* This method will remove named property from given object | ||
* | ||
* @param {Object} obj - the object to remove property from | ||
* @param {String} prop - name of property to remove | ||
*/ | ||
|
||
function removeProperty(obj, prop) { | ||
delete obj[prop] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import test from 'ava' | ||
import {removeProperty} from '../src' | ||
|
||
test('Remove a property from object', t => { | ||
const obj = {fname: 'foo', lname: 'bar'} | ||
const prop = 'lname' | ||
const expected = {fname: 'foo'} | ||
const actual = obj | ||
removeProperty(obj, prop) | ||
t.deepEqual(actual, expected) | ||
}) |