🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Get All Elements from an Array

6 replies
Last updated: Jan 22, 2022
Hi !
I got what I wanted data wise using this query, but I just got 1 element out of the array, I was wondering how to do the same but to get information from every element of the array:

Thanks in advance!
🙏
Jan 22, 2022, 12:27 AM
Hey there! To clarify, are you not getting all of your
events
or all of your
registers
? If it's the latter, you're currently specifying
registers[0]
, which would only return the first index of the array.
Jan 22, 2022, 12:29 AM
This is what i’m getting. Just the first element as the query says (I did it that way cause I’m trying to get all the information, but that’s the most that I’ve got haha 😅)
Jan 22, 2022, 12:32 AM
If you remove the
0
, you should get all of your
registers
array back even if you are specifying a projection.
Jan 22, 2022, 12:34 AM
When I did this:

*[type == "event"]{
  ..., 
  registers->
}
It returned null for registers
Jan 22, 2022, 12:34 AM
It worked, thank you very much! 🤘
Jan 22, 2022, 12:37 AM
You're welcome!
Jan 22, 2022, 12:37 AM

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?