Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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?