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

219
Views
cómo agregar propiedades a cada uno de los objetos según el valor temporal, pero no cambie el orden de los objetos

Estoy trabajando con una variedad de objetos y necesito agregar la propiedad 'orderTemp' a cada uno de los objetos según el valor temporal donde no necesito cambiar el orden de los objetos

Mi matriz inicial de objetos se ve así

 [ { humidity: 95, location: 'Konstanz', pressure: 1003, temp: 22.46 }, { humidity: 45, location: 'India', pressure: 1014, temp: 2.23 }, ... ];

Así que mi conjunto resultante de objetos se vería así

 [ { humidity: 95, location: 'Konstanz', pressure: 1003, temp: 22.46, orderTemp: 2 }, { humidity: 45, location: 'India', pressure: 1014, temp: 2.23, orderTemp: 1 }, ... ];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes hacer algo como esto:

 // get list of all temperature values and sort it const temperatures = data.map(item => item.temp).sort(); // if you want to change source data data.forEach(item => item.orderTemp = temperatures.indexOf(item.temp)); // if you want create new array with this additional field in object const newData = data.map(item => ({ ...item, orderTemp: temperatures.indexOf(item.temp) }) );
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!