I have 2 observables that are listening for a database call respectively. I need to merge the 2 arrays together. If I have the following arrays
array1 = [{id: 1, content1: "string"}, {id: 2, content2: "string"}, {id: 3, content3: "string"}]
array2 = [{id: 1, contentX: "string"}, {id: 2, contentY: "string"}, {id: 3, contentZ: "string"}]
I want to merge them together so that I get a single observable array like this:
[{id:1, content1:"string", contentX:"string"}, {id:2, content2:"string", contentY:"string"}, {id:3, content3:"string", contentZ:"string"}]
I have some code but I'm really confused on how to proceed, I can't seem to find the right operators or chain them properly, does anyone have a good explanation on how to proceed? This is what I have so far, but literally don't know how to go on.
const observable1 = getDataFromDb1();
const observable2= getDataFromDb2();
observable1 .pipe(
combineLatest(observable2),
flatMap(x => {
//what to do here???
})
).subscribe(
(value)=>{
console.log(value);
}
)
Thanks for your time
[{id: 1, content1: "string"}]
or an object{id: 1, content1: "string"}
? – CozyAzureobservable1
andobservable2
emit their values (individually or all in one go)? And how is the relationship defined? Will there always be a id matching record in both sets? What should happen if their isn't? – Yoshi