
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGROQ doesn't support negative indices in array slicing the way you might expect from other languages. Your syntax links[(count(links) - 10))...count(links))] has a couple of issues.
To get the last 10 elements of an array in GROQ, you have a few options:
GROQ does support negative indices! According to the GROQ pipeline components documentation, negative range endpoints are based at the end of the array. You can use:
*[_type == "archives"] {
title,
slug,
"lastTenLinks": links[-10..-1]
}This syntax [-10..-1] means "from the 10th-to-last element to the last element."
If you want to be more explicit or if negative indexing doesn't work in your GROQ version, you can reverse the array and take the first 10:
*[_type == "archives"] {
title,
slug,
"lastTenLinks": links | order(@) | [0...10]
}However, this approach may not preserve the original order.
Your query links[(count(links) - 10))...count(links))] has these problems:
(count(links) - 10)) with double closing parenscount(links) in the slice syntax.. (two dots) to include both endpoints, or ... (three dots) to exclude the right endpointUse the negative index approach with two dots (which includes both endpoints):
*[_type == "archives"] {
title,
slug,
links[-10..-1]
}This will gracefully handle arrays shorter than 10 elements - it'll just return whatever is available. The negative indices are based at the end of the array, so [-10..-1] gives you the last 10 items (or fewer if the array is shorter).
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store