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

251
Vistas
How to replace array values with another arrays values in Angular8

I have two sample data named oldArray and newArray.

I want to replace oldArray objects with newArray objects if makeLineName and makeProcessTypeId of both oldArray and newArray is same.

For Ex - In oldArray, we have TestDemo1 and Test565 makeLineName available and same TestDemo1 and Test565 makeLineName available in newArray also, So i want to search newArray for this TestDemo1 and Test565 makeLineName and if same makeLineName availalble in newArray than replace the fields values of oldArray makelinename with same makelinename object of newarray.

and if same makelinename is not available in newArray, then oldArray object which not matched than it will remain as it is.

oldArray = [
      {       
        makeLineName: "TestDemo1",
        avtBCT: 80,
        MaxBCT: 80
      },
      {      
        makeLineName: "Test565",
        avtBCT: '',
        MaxBCT: ''
      },
      {      
        makeLineName: "Luck", 
        avtBCT: 60,
        MaxBCT: 60
      }
    ];

    const newArray = [
      {       
        makeLineName: "TestDemo1",
        avtBCT: 500,
        MaxBCT: 500
      },
      {      
        makeLineName: "Test565",
        avtBCT: 600,
        MaxBCT: 600
      }
    ];

Expected Output =

 filteredData = [
      {       
        makeLineName: "TestDemo1",
        avtBCT: 500,
        MaxBCT: 500
      },
      {      
        makeLineName: "Test565",
        avtBCT: 600,
        MaxBCT: 600
      },
      {      
        makeLineName: "Luck", 
        avtBCT: 60,
        MaxBCT: 60
      }
    ];
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You can use this line of code :

let resultArray = oldArray.map(el => newArray.find(f => f.makeLineName == el.makeLineName) ?? el);

to solve you error try :

let resultArray = oldArray.map(el =>  {
    let newElement = newArray.find(f => f.makeLineName == el.makeLineName);
    return newElement ? newElement : el;
});
about 4 years ago · Santiago Gelvez 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