How to get the first element of an array?


I know it’s a stupid question, but I couldn’t handle it.
I don’t know how to write it correctly.

Describe the issue/error/question

How to get the first element of an array?

I need to eventually get: 1976

It should be something like this:
{{ Object.keys($json[“body”][“img”]).join(', ‘).split().first() }}
{{ Object.keys($json[“body”][“img”]).join(’, ‘).split().[0] }}
{{ Object.keys($json[“body”][“img”]).join(’, ').split().items[0] }}

Thank you so much for your time and help!

Hey @Mikhail,

You should be able to use the index (position) to get it, {{ $json.body.img[0] }}

1 Like

Hey @Jon ! Thank you so much for your reply!

Yes, I thought about it, but all the time I have a problem - how to write it))))

Again, somewhere in the syntax is inaccurate:

Although all the elements are popping up:

Ah I see, So img isn’t actually an array. I guess what you could do is turn it into an array then use Item Lists to turn it into items so you can use it like this…

1 Like

I changed it a bit, because I only need the ID of the first element.

{{ Object.values($json.body.img) }}
{{ $json.image[0].id }}

:+1: :grinning:
Thank you so much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.