I am in need of a solution to merge two arrays into one using TypeScript.
First Array Object:
export interface Item{
Label : string,
Code : string,
Price : number,
}
Second Array Object:
export interface Amount
{
Code : string,
Amount: number
}
Result Array Object:
export interface CombinedList{
Code : string,
ItemAmount : number,
ItemPrice : number
}
In the resulting array, I aim to combine the Item and Amount arrays based on their shared Code values. (Each Code has 3 matching elements in Item and Amount arrays).
Example:
ItemsArray : Item[] =
[{ Label : "One", Code : "ONE", Price : 5,86},
{Label : "Two", Code : "TWO", Price : 9,99},
{Label : "Three", Code : "THR", Price : 752}]
AmountsArray : Amount[] =
[{ Code : "ONE", Amount : 120},
{Code :"TWO", Amount : 250},
{Code :"THR", Amount : 165}]
And the desired result is:
CombinedArray : CombinedList[] =
[{Code : "ONE", ItemAmount : 120, ItemPrice: 5,86 },
{Code :"TWO", ItemAmount : 250, ItemPrice: 9,99},
{Code :"THR", ItemAmount : 165, ItemPrice: 752}]