Skip to content
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

Closed
nrukavkov opened this issue Sep 24, 2021 · 4 comments · Fixed by #23
Closed

Remove from array #20

nrukavkov opened this issue Sep 24, 2021 · 4 comments · Fixed by #23
Labels
enhancement New feature, or improvements to exisiting features

Comments

@nrukavkov
Copy link

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");

@khalby786
Copy link
Owner

khalby786 commented Sep 24, 2021 via email

@khalby786 khalby786 pinned this issue Sep 30, 2021
@khalby786 khalby786 changed the title Remove from array [HACKTOBERFEST] Remove from array Sep 30, 2021
@khalby786 khalby786 changed the title [HACKTOBERFEST] Remove from array [Hacktoberfest Opportunity] Remove from array Sep 30, 2021
@khalby786 khalby786 changed the title [Hacktoberfest Opportunity] Remove from array Remove from array Sep 30, 2021
@khalby786 khalby786 unpinned this issue Sep 30, 2021
@Kerrders
Copy link

Kerrders commented Oct 1, 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))

@khalby786
Copy link
Owner

Is anyone interested in implementing this feature resulting in a Hacktoberfest PR? ;)

@wh0 wh0 mentioned this issue Oct 2, 2021
@khalby786 khalby786 added the enhancement New feature, or improvements to exisiting features label Oct 2, 2021
@yucopowo
Copy link

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
Labels
enhancement New feature, or improvements to exisiting features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants