Reference data key instead of value?

How do I reference a data key instead of a data value? I want a hover on the img to show the “type1” key instead of the corresponding value. (EDIT: This is inside a v-for looping through an array of objects)

<img :src="data.img" :title="data.type1.key" />

What is your data structure? Is this part of a v-for loop?

Sorry. Yes it is!
The v-for is looping through an array of objects.

you could get the key of an iterable object in the v-for using for… of synax like so:

 <div v-for="(value, key) of someObject">{{ value }} {{ key }}</div>

for… of:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

or you could try converting your objects to tuples wtith Object.items(yourObject), and access it by index.

1 Like