-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove from array #20
Labels
enhancement
New feature, or improvements to exisiting features
Comments
Sure, thanks for the suggestion, I'll add it!
…On Fri, Sep 24, 2021, 7:55 PM Nikita Rukavkov ***@***.***> wrote:
Following the instruction, we can add to the array. But I could not find a
way how to remove an element from array.
// push stuff to an array for a particular key
await db.push("transformers", "optimus prime");
await db.push("transformers", "bumblebee");
await db.push("transformers", "iron hide");
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#20>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJFPUQ4KPWYG3WCJN2374OTUDSNQBANCNFSM5EWIA45Q>
.
|
khalby786
changed the title
[HACKTOBERFEST] Remove from array
[Hacktoberfest Opportunity] Remove from array
Sep 30, 2021
khalby786
changed the title
[Hacktoberfest Opportunity] Remove from array
Remove from array
Sep 30, 2021
I just use something like this: const transformers = await db.get("transformers");
const transformerToRemove = "optimus prime";
await db.set(`transformers`, transformers.filter(transformer=> transformer !== transformerToRemove)) |
Is anyone interested in implementing this feature resulting in a Hacktoberfest PR? ;) |
Merged
khalby786
added
the
enhancement
New feature, or improvements to exisiting features
label
Oct 2, 2021
jsoning.prototype.remove = async function(key, callback) {
const array = await this.get(key);
return this.set(key, array.filter(item => !callback(item)))
};
await db.remove('jobs', (job) => {
return job.id === 'xxxxxxx';
});
jsoning.prototype.update = async function(key, callback) {
const array = await this.get(key);
return this.set(key, array.map(item => callback(item) || item))
};
await db.update('jobs', (job) => {
if(job.id === 'xxxxxxx') {
return {
...job,
...params,
}
}
return job;
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following the instruction, we can add to the array. But I could not find a way how to remove an element from array.
The text was updated successfully, but these errors were encountered: