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

213
Views
'Mover' propiedades de un objeto a un nuevo objeto, basado en un tercer objeto

Tengo un objeto que contiene múltiples propiedades. Para una lista dada de accesorios en un tercer objeto, quiero 'mover' las propiedades del objeto original y colocarlas en un nuevo objeto.

Tengo una forma 'manual' de hacer esto en este momento, algo como lo siguiente. Sin embargo, esto crea 2 objetos nuevos, en lugar de simplemente 'mover' algunas de las claves:

 let pets = { 'cat': {}, 'dog': {}, } let animals = { 'cat': 'black', 'dog': 'white', 'whale': 'blue', 'albatross': 'grey', } let aPet = {} let notAPet = {} for (let [key, val] of Object.entries(animals)) { if (key in pets) { aPet[key] = val } else { notAPet[key] = val } }

¿Hay una manera más "corta" de lograr lo anterior, preferiblemente solo creando aPet mientras que animals terminan siendo equivalentes a notAPet ?

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

0

Puede usar el operador de eliminación :

 let pets = { 'cat': {}, 'dog': {}, } let animals = { 'cat': 'black', 'dog': 'white', 'whale': 'blue', 'albatross': 'grey', } let aPet = {} let notAPet = {} for (let [key, val] of Object.entries(animals)) { if (key in pets) { aPet[key] = val delete animals[key] } } console.log(aPet, animals)

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!