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

20 replies
Last updated: Jan 28, 2026
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:

  1. Array index syntax: Use 'vehicleContent.bilder.0' with dot notation rather than bracket notation [0]. This is the standard way to access array items in preview configuration.

  2. Media value: Pass heroImage directly instead of wrapping it in a template literal (${heroImage}). The media property expects the actual image object, not a string representation of it.

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

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.

Was this answer helpful?