Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Delete the object in place from an array: JS

I am having an array of objects with the following structure:

const timeOptions = [
  { key: "all", value: "all", text: "All" },
  { key: "month", value: "month", text: "Month" },
  { key: "year", value: "year", text: "Year" }
];

I am creating a new object with this timeOptions being a value of a field in it. How to remove the object with key "all" in-place while creating the object itself

const values = {
  timeVal: {
    field: "timestamp",
    label: "Timestamp",
    options: timeOptions
  }
};

Code that I tried


const values = {
  timeVal: {
    field: "timestamp",
    label: "Timestamp",
    options: timeOptions.forEach((k) => delete k["key"] === "all")
  }
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Using Array#filter:

options: timeOptions.filter(({ key }) => key !== 'all')
about 4 years ago · Juan Pablo Isaza Report

0

If I understand you correctly, you need filter

const values = {
 timeVal: {
 field: "timestamp",
 label: "Timestamp",
 options: timeOptions.filter((k) =>  k["key"] !== "all")
}

};

This will copy all except the one with key "all"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!