I have array like below
data() {
return {
shoppingItems: [
{name: 'apple', price: '10'},
{name: 'orange', price: '12'}
]
}
}
I am trying to iterate like below
<ul>
<li v-for="item in shoppingItems">
{{ item.name }} - {{ item.price }}
</li>
</ul>
I am getting output like below
- apple - 10
- orange - 12
But I would like to get output like below
- name - apple, price - 10 //I would like to print key dynamically
- name - orange, price - 12
You can iterate over the keys/values with this :
You can also have the index of the current key :
Object.Keys(Object) returns an array containing all the key of the object. Now you can use index to fetch the desire key -
You can use
(key,value)
pair infor
loop