Q:

Create a Json structure from arrays by code - Typescript

I must create a Json object that represent a Sandwich configuration (bread, meat, sauces etc...) from different arrays that contains the ingredients for each category (1 array for bread, 1 for meat etc...) like this {name: 'x', price: 'y'} 
The categories are defined but each array can have a different number of elements.
It's possible to obtain, starting from these arrays, something like that by code? I need this to make a recap of my sandwich in the cart page after the user choose all the ingredients. (each cat_1 it's a type of ingredient).
sandwich{
"cat_1": {[
        {
            "name": "x",
            "price": "x"
        }
    ]
},
"cat_2": {[
        {
            "name": "x",
            "price": "x"
        }
    ]

},
"cat_3": {[
    {
        "name": "x",
            "price": "x"
    },
    {
        "name": "x",
        "price": "x"
    },
    {
        "name": "x",
        "price": "x"
    }
    ]

},
"cat_4": {[
        {
            "name": "x",
            "price": "x"
        },
        {
            "name": "x",
            "price": "x"
        }
    ]
},
"cat_5": {[
        {
            "name": "x",
            "price": "x"
        },
        {
            "name": "x",
            "price": "x"
        },
        {
            "name": "x",
            "price": "x"
        }
    ]
}      

}
I don't post any code beacuse I don't know what can help.
Actually, I push all my arrays into a big array and I have something like that, but it's a lot different from what I want achieve.
[{
    "name": "Montanaro",
    "price": "5.00"
}, {
    "name": "Manzo",
    "price": "5.00"
}, {
    "name": "Fossa",
    "price": "1.00"
}, {
    "name": "Caciotta",
    "price": "1.00"
}, {
    "name": "Guacamole",
    "price": "0.50"
}, {
    "name": "Olive ascolane",
    "price": "1.00"
}, {
    "name": "Mozzarelline fritte",
    "price": "0.50"
}, {
    "name": "Onion Rings",
    "price": "1.00"
}]

I'm not a json expert so I don't know where to start...
Thank you to everyone that could help me.
Have a good day

A:

Have you tried to split the ingredients and add an element from the list for each sandwich?
let breads = [{name: "bread1", price: 1.00}, {name: "bread2", price: 2.00}, {name: "bread3", price: 3.00}];
let meats  = [{name: "meat1" , price: 1.00}, {name: "meat2" , price: 2.00}, {name: "meat3" , price: 3.00}];
let sauces = [{name: "sauce1", price: 1.00}, {name: "sauce2", price: 2.00}, {name: "sauce3", price: 3.00}];

let s1 = {
  bread : breads[Math.floor(Math.random()*breads.length)],
  meats : meats[Math.floor(Math.random()*meats.length)],
  sauces : sauces[Math.floor(Math.random()*sauces.length)]
}
let sandwich = {s1};

console.log(sandwich);

Here is an example: https://codepen.io/WildLlama/pen/VVLYmL?editors=0011

