I have group by an array of elements based on their resturant id.
function grouparray(list,key)
{
return list.reduce(function(rv,x){
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
},{});
};
var group = grouparray(cartArray,"resturantid");
it gives an output like
{1: Array(3), 2: Array(3)}
It is array inside an array.
now i want to loop this inside backticks Full Code:
function displaycheckout()
{
var cartArray = shoppingCart.listCart();
function grouparray(list,key)
{
return list.reduce(function(rv,x){
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
},{});
};
var group = grouparray(cartArray,"resturantid");
for(i in group)
{
output +=
` Resturant Name : ${group[i][0].resturant}
`
for(a in group[i]){
`
menu ${group[i][a].food}
`
}
}
But it doesn't work