
Research
/Security News
11 Malicious Go Packages Distribute Obfuscated Remote Payloads
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Delete a key from a deeply nested JavaScript object.
There are a few other libs that already aid in deleting keys from objects. But none of them iteratively deletes the key if one of the nested objects is an array.
The following are the highlights of this delete-key
library.
del-key
differs from lodash's _.unset()
method)$ npm install --save del-key
deleteKey(obj, pathToDelete)
obj - the object that has the key to be deleted
pathToDelete - the path to the key in the object in string notation
See examples below for more info.
import deleteKey from 'del-key'; // ES6 style import
// const deleteKey = require('del-key'); // ES5 style import
const obj = {
nestedKey: {
poorKey: 'hello',
luckyKey: 'hi'
}
}
deleteKey(obj, 'nestedKey.poorKey') // =>obj.nestedKey = { luckyKey: 'hi' }
//------------------------------------
const obj = {
nestedArray: [{
poorKey: 'first hello',
luckyKey: 'first hi'
}, {
poorKey: 'second hello',
luckyKey: 'second hi'
}]
}
deleteKey(obj, 'nestedArray[0].poorKey')
// =>obj.nestedArray[0] = { luckyKey: 'first hi' }
// =>obj.nestedArray[1] = { poorKey: 'second hello', luckyKey: 'first hi' }
//------------------------------------
const obj = {
nestedArray: [{
poorKey: 'first hello',
luckyKey: 'first hi'
}, {
poorKey: 'second hello',
luckyKey: 'second hi'
}]
}
deleteKey(obj, 'nestedArray.poorKey') // => iteratively removes poorKey from each item in nestedArray
// =>obj.nestedArray[0] = { luckyKey: 'first hi' }
// =>obj.nestedArray[1] = { luckyKey: 'first hi' }
MIT © Dineshkumar Pandiyan
FAQs
Safely delete a deeply nested key in an object
We found that del-key demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).