Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

How to append an array in GROQ?

1 replies
Last updated: Jan 25, 2022

You can use array splatting:

[...a, ...b]
will concatenate
a
and
b
, and those can be queries.

Jan 25, 2022, 2:08 PM

So this should work:

"items": [
  *[_type == "groupsPage"][0] {
    "title": "Overview",
    "url": "/aag-ugsg/"
  },
  ...(*[_type == "groupsPages"] {
    title,
    "url": "/aag-ugsg/" + slug.current
  })
]

Jan 25, 2022, 2:09 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.