I have an array called dealers in a JSON document that contains several object as shown below.
"dealers" : [ 
    {
        "name" : "BMW Dealer",
        "country" : "Belgium",
        "code" : "123"
    },
        {
        "name" : "Audi Dealer",
        "country" : "France",
        "code" : "124"
    },
        {
        "name" : "VW Dealer",
        "country" : "Germany",
        "code" : "125"
    }
]
I also have an interface type as shown below and a variable of this interface type.
interface IDealer extends IZone {
    dealerName: string;
    dealerCode: string;
    dealerCountry: string
}
var countryDealers IDealer;
I'd like to iterate through the dealers array of objects and populate the countryDealers variable.
How can I achieve this please?
have you tried with the .map() function of ES6 ?
like:
    let myInterfacesArray = countryDealers.map(xx=>{
    return <IDealer>
    {
         dealerName : xx.name,
         dealerCode : xx.code,
         dealerCountry : xx.country
          // and so on
     };
  });
Hope it help you!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With