0
I have the following objects:
var category = [
    {"category" : "fruity"},
    {"category" : "Cakes"}
]
and
var products = [
    {"description" : "Apple", "price" : 12.99, "category" : "Fruity"},
    {"description" : "Peach", "price" : 12.99, "category" : "Fruity"},
    {"description" : "Cake one", "price" : 12.99, "category" : "Cake"}
]
I intend to make this information available in the following format:
[
    {
        "category": "fruity",
        "products": [
            {
                "description" : "Apple",
                "price" : 12.99
            },
            {
                "description" : "Peach",
                "price" : 17.99
            }
        ]
    },
    {
        "category": "Cakes",
        "products": [
            {
                "description" : "Cake one",
                "price" : 12.99
            }
        ]
    }
]
I am a while away to work on it and the result has not been satisfactory. Here is my code:
var j=0;
var i=0;
var entraP = { prod : [] }
if (category[i].category == products[j].category ){
  entrarP.c = category[i].category;
  while(category[i].category == products[j].category ){
    entrarP.prod.push(products[j]);
    j+=1;
  }
  i+=1;
}
console.log(entrarP);
I appreciate a help.
thanks for the help. Works perfectly.
– C-lio Garcia