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 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?