I am developing a new angular 8 project where in my component, I get json data from 2 different services. the data is array of objects. I want to join the objects in the array and post it back to the database.
here is the code
import { Component , OnInit} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
// data comes from Persons Service
person = [
{name: "john", id: 1, joined: "2018"},
{name: "sarah", id: 2, joined: "2019"}
]
// data comes from salary Service
salary = [
{name: "john", id: 1, salary: 3000},
{name: "sarah", id: 2, salary: 5000}
]
personWithSalary;
ngOnInit(){
}
}
How can I combine this data together and map the salaries to correct person so it goes into a new array like this:
personWithSalary = [
{name: "john", id: 1, joined: "2018", salary: 3000},
{name: "sarah", id: 2, joined: "2019", salary: 5000}
]
salaryalready has the desired data