Closed nrukavkov closed 2 years ago
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 https://github.com/khalby786/jsoning/issues/20, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJFPUQ4KPWYG3WCJN2374OTUDSNQBANCNFSM5EWIA45Q .
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? ;)
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;
});
Following the instruction, we can add to the array. But I could not find a way how to remove an element from array.