[Vuejs]-TypeError: Cannot read property '0' of undefined inside v-for

4👍

You’re getting that error because some of the objects have sight.photos as undefined. You could add a check like this before accessing the zeroth index:

<div @click='selectSight(index)' v-for='(sight, index) in sights'>
    {{ sight.name }}
    {{ sight.photos && sight.photos.length > 0 ? sight.photos[0].photo_reference : '' }}
</div>
👤adiga

Leave a comment