Finding Total Elements in Array Property

2 replies
Last updated: Apr 8, 2021
Hi,Can someone help me with finding total elements in array property? If I have a dataset like this

  author: "Mike",
  books: [1, 2, 3]
  author: "Kira",
  books: [4, 5, 6, 7]
How can I get the total books? so the result like
totalBooks: 7
.I try
but the result is two.Thanks.
Apr 8, 2021, 1:02 AM
With API version 2021-03-25 you should be able to do this:
. The final
at the end there causes the books-array to be flattened.
Apr 8, 2021, 10:47 AM
Ah...sweet. Thank you very much Magnus.
Apr 8, 2021, 11:26 AM – build remarkable experiences at scale

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