I have an array of products in VueJs called: top_produtos
each product has another array called attributes with several attributes, for example:
top_produtos: [
{
"produto": {
"ASIN": "B0CCJWFWWN",
},
"detalhes": {
"results": [
{
"attributes": [
{
"id": "BRAND",
"name": "Marca",
"value_id": "3",
"value_name": "Philips"
},
{
"id": "MODEL",
"name": "Modelo",
"value_id": "28214759",
"value_name": "43PFG6918"
},
]
}
],
}
},
{
"produto": {
"ASIN": "B0BW1X752N",
},
"detalhes": {
"results": [
{
"attributes": [
{
"id": "BRAND",
"name": "Marca",
"value_id": "479",
"value_name": "Philco"
},
{
"id": "LINE",
"name": "Linha",
"value_id": "19745424",
"value_name": "Smart Tv Series"
},
{
"id": "MODEL",
"name": "Modelo",
"value_id": "19724299",
"value_name": "PTV32G7PR2CSBLH"
},
]
}
],
}
}
]
I need to filter and recreate a new array containing all the same products, however they have the same attributes. Some products have 8 of the same attributes, others have 4, and so on. I need to recreate the same array and keep the attributes that exist in all of them.
I made several attempts with filter(), map() and reduce(). However, the more I did, the less I understood what was happening and everything became very confusing.
Marcos Nobrega is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.