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

193
Views
How to create new object from old one with filtered values

I have an object:

const items = {
  a: [3,5],
  b: [6,7,8],
  c: [0,10,1111]
}

and the array:

const existing = [3,8]

I'd like to create a new object, but without values that are included in the existing array. I mean this one:

const newItems = {
  a: [5],
  b: [6,7],
  c: [0,10,1111]
}

Please about the tips!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

    const items = {
      a: [3,5],
      b: [6,7,8],
      c: [0,10,1111]
    }
    
    const existing = [3,8]
    
    
    const result = Object.keys(items).reduce((acc, key ) => {
      acc[key] = items[key].filter((item)=> !existing.includes(item))
      return acc;
    }, {})
    
    console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

You can use Object.entries and Object.fromEntries along with filter to get the required result.

const items = {
  a: [3, 5],
  b: [6, 7, 8],
  c: [0, 10, 1111],
}

const existing = [3, 8]

const newEntries = Object.entries(items).map(([key, value]) => [
  key,
  value.filter((x) => !existing.includes(x))
])


const newObject = Object.fromEntries(newEntries)
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!