Hi, in my service file, I would like to get all productnames from the productlist array
here is my data:
export const PACKAGEPRODUCTS: any = [ { packagename: 'Package 1' }, { productlist: [ { productname: 'product1' }, { productname: 'product2' }, { productname: 'product3' }, ] }, { packagename: 'Package 2' }, { productlist: [ { productname: 'product3' }, { productname: 'product6' }, ] }, { packagename: 'Package 3' }, { productlist: [ { productname: 'product6' }, { productname: 'product9' } ] }, { packagename: 'Package 4' }, { productlist: [ { productname: 'product2' }, { productname: 'product3' }, { productname: 'product5' } ] } ];
I have written something like what I require in PHP but need this in TypeScript
foreach (packages as package){
foreach ($package['products'] as $product) {
if($fullProductList.indexOf($product) == -1) {
$fullProductList.push($product);
}
}
}
So, I have made a start by writing the following:
getFullProductList() {
this.packageproducts.forEach(
//if condition here
);
return this.packageproducts.slice();
}