How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

How to access first image from array in Sanity preview select syntax?

20 repliesLast updated: Nov 29, 2025

I am trying to get a media thumbnail/preview to work in the document list, but I am struggling to grab image 0 from an array. Does anyone have any pointers on what the syntax needs to be?
My preview config (“heroImage”, which I am trying to make work…)

preview: {
    select: {
      status:'vehicleContent.synlighet.status',
      modelName: 'vehicleContent.typeinfo.modellbetegnelse',
      licensePlate: 'vehicleContent.identitet.licensePlate',
      manufac: 'vehicleContent.typeinfo.manufacturer.label',
      heroImage: 'vehicleContent.bilder[0]',
      year:'vehicleContent.datoer.FirstRegisterDate'
    
    },
    prepare( {status, heroImage, modelName, year, licensePlate,manufac}) {
      return {
        media: `${heroImage}`,
        title: `${licensePlate}  -  ${status.toUpperCase()}`,
        subtitle:  `${year ? year.split('-')[0] : '' } ${manufac ? manufac : ''} ${modelName ? modelName :''}`

      }
    }
}
}

AI Update

Looking at your code, you're very close! The syntax for accessing array items in Sanity's preview select is to use dot notation with the index number, like 'vehicleContent.bilder.0' instead of 'vehicleContent.bilder[0]'.

Here's your corrected preview config:

preview: {
  select: {
    status: 'vehicleContent.synlighet.status',
    modelName: 'vehicleContent.typeinfo.modellbetegnelse',
    licensePlate: 'vehicleContent.identitet.licensePlate',
    manufac: 'vehicleContent.typeinfo.manufacturer.label',
    heroImage: 'vehicleContent.bilder.0',  // Changed from [0] to .0
    year: 'vehicleContent.datoer.FirstRegisterDate'
  },
  prepare({status, heroImage, modelName, year, licensePlate, manufac}) {
    return {
      media: heroImage,  // Remove the template literal - just pass the value directly
      title: `${licensePlate}  -  ${status.toUpperCase()}`,
      subtitle: `${year ? year.split('-')[0] : ''} ${manufac ? manufac : ''} ${modelName ? modelName : ''}`
    }
  }
}

Two key changes:

If your image field is an image type with an asset reference, you might also want to be more specific and use 'vehicleContent.bilder.0.asset' to directly access the asset, though often just .0 works fine depending on your schema structure.

Show original thread
20 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions