I've got an array of objects:
array = [
{ age: 5, name: foo },
{ age: 5, name: bar },
{ age: 8, name: baz }
]
I loop over the array like this:
<div v-for="(arr, index) in array" :key="index">
<h5>age: {{ arr.age }}</h5>
<ul>
<li>{{ arr.name }}</li>
</ul>
</div>
which renders like this:
<div>
<h5>age: 5</h5>
<ul>
<li>foe</li>
</ul>
</div>
<div>
<h5>age: 5</h5>
<ul>
<li>bar</li>
</ul>
</div>
<div>
<h5>age: 8</h5>
<ul>
<li>baz</li>
</ul>
</div>
however I want the arrays with the same age to merge like this:
<div>
<h5>age: 5</h5>
<ul>
<li>foe</li>
<li>bar</li>
</ul>
</div>
<div>
<h5>age: 8</h5>
<ul>
<li>baz</li>
</ul>
</div>
I'm thinking about making a separate object and merging the content of the arrays if the age key/value pairs are the same. How can I obtain this?