-4
Hello, you can use reduce to create a new array grouped by categories.
See the example below:
var dados = [
{
nome: 'cerveja',
categoria: 'bebida'
},
{
nome: 'suco',
categoria: 'bebida'
},
{
nome: 'joelho',
categoria: 'salgado'
},
{
nome: 'pastel',
categoria: 'salgado'
}
]
var novoArray = dados.reduce(function(prev,curr){
prev[curr.categoria] = prev[curr.categoria] || [];
prev[curr.categoria].push(curr);
return prev;
},{});
console.log(novoArray)
That what? In the title you ask in Javascript, in the body of the question in PHP, but in no time you say what you really want to do. Please read the [Ask] guide and try to improve your question.
– Woss
I’m wanting in Javascript
– Gustavo Gabriel
This image shows the part you’ve already done? Where exactly are you having difficulties?
– bfavaretto
So I just did the design part and I want the products to be separated by categories like in the image above.
– Gustavo Gabriel