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

249
Views
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 answers
Answer question

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 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!