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

128
Vistas
How to dynamically change the key of the objects and merge multiple array like objects into single array using java script?

I have done the pre-processing calculation using javascript and finally have the following different arrays.

var medianArray = [{ Thomas: 94, Diana: 94, Claura: 93, Chandler: 91 }];
var q1Array = [ { Thomas: 93, Diana: 94, Claura: 92, Chandler: 91 } ];
var q3Array = [{ Thomas: 95, Diana: 95, Claura: 93, Chandler: 93 }];
var outArray = [{ Thomas: [], Diana: [85, 86, 87, 91], Claura: [94, 94, 94], Chandler: [75, 86] }];
var result = [];

now, I am trying to bring into a single array with meaningful keys and values in the below format.

[{"stdName": "Thomas", "q1" : 93, "q3" : 95, "median": 94, "outliers": []},
{"stdName": "Diana", "q1" : 93, "q3" : 95, "median": 94, "outliers": [85, 86, 87, 91]},
{"stdName": "Claura", "q1" : 93, "q3" : 95, "median": 93, "outliers": [94, 94, 94]},
{"stdName": "Chandler", "q1" : 93, "q3" : 95, "median": 91, "outliers": [75, 86]}]

I have searched tried multiple online resources and references of reduce(), map(), etc., but somehow not getting how to change the key name solutions.

[].concat(q1Array, q3Array, medianArray,outArray).forEach(function (items) {
    //logic try to add and not getting idea to proceed.
    if (!this[items]) {            
        result.push();
    }   

}, Object.create(null));

console.log(result);

I hope you kind of JavaScript people on Stack Overflow can help me out with this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If all arrays have the same amount of names you can first extract all names with Object.keys(). Afterwards loop over all the names and reduce them into their own object.

var medianArray = [{ Thomas: 94, Diana: 94, Claura: 93, Chandler: 91 }];
var q1Array = [ { Thomas: 93, Diana: 94, Claura: 92, Chandler: 91 } ];
var q3Array = [{ Thomas: 95, Diana: 95, Claura: 93, Chandler: 93 }];
var outArray = [{ Thomas: [], Diana: [85, 86, 87, 91], Claura: [94, 94, 94], Chandler: [75, 86] }];

const names = Object.keys(medianArray[0]);

const result = names.reduce((acc, name) => {
  acc.push({
    stdName: name,
    q1: q1Array[0][name],
    q3: q3Array[0][name],
    median: medianArray[0][name],
    outliers: outArray[0][name],
  });
  
  return acc;
}, []);

console.log(result);

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