✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

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– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?