I have an array filled with definitions. How can I use Vue.js to iterate through this array and create a glossary list organized by letters?
Desired Output:
A
- Aterm: A definition of aterm
B
- Bterm: A definition of bterm
C
- Cterm: A definition of cterm
- Cterm: A definition of cterm
- Cterm: A definition of cterm
Y
- Yterm: A definition of yterm
- Yterm: A definition of yterm
Z
- Zterm: A definition of zterm
<div id="app" class="container">
<div v-for="(item, index) in fields" :key="index">
<span>{{ item.Term.charAt(0) }}
<h3>{{ item.Term }}</h3>
<p>{{ item.Definition }}</p>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
parentMessage: 'Parent',
fields: [
{ Term: 'Aterm', Definition: 'A definition for aterm' },
{ Term: 'Bterm', Definition: 'A definition for bterm' },
{ Term: 'Cterm', Definition: 'A definition for cterm' },
{ Term: 'Cterm', Definition: 'A definition for cterm' },
{ Term: 'Cterm', Definition: 'A definition for cterm' },
{ Term: 'Mterm', Definition: 'A definition for mterm' },
{ Term: 'Yterm', Definition: 'A definition for yterm' },
{ Term: 'Yterm', Definition: 'A definition for yterm' },
{ Term: 'Zterm', Definition: 'A definition for zterm' }
]
},
methods: {
// do something
}
})
</script>