I have this products array in an angular 2 component:
products = [{name: "product1", product_properties: [{name: "color", value: "blue"}, {name: "size", value: "small"}]},
{name: "product2", product_properties: [{name: "color", value: "yellow"}, {name: "size", value: "medium"]},
{name: "product3", product_properties: [{name: "color", value: "green"}, {name: "size", value: "large"},
{name: "product4", product_properties: [{name: "color", value: "green"}, {name: "size", value: "small"}]}
{name: "product5", product_properties: [{name: "color", value: "yellow"}, {name: "size", value: "medium"}]
What is the most efficient way to loop over this array and derive an array which looks like the one below using typescript or javascript:
derivedArray = [{property_name: "color", values: ["blue", "yellow", "green"]},
{property_name: "size", values: ["small", "medium", "large"]}]
derivedArray? it's all uniqe values from all products or what ?product_propertiesto clarify on expected handling of duplicates. Theproperty_names and their correspondingvalues should be unique even if the original array has duplicates