Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
how to add property to each of the objects based on temp value ,but don't change the order of objects

I am working with a array of objects and i need to add property 'orderTemp' to each of the objects based on temp value where i don't need to change the order of objects

My initial array of objects looks like so

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

So my resulting array of objects would look something like so

[
  { 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 Respuestas
Responde la pregunta

0

You can do something like this:

// 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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda