Skip to content

How to get last element of array? #25673

Answered by weide-zhou
Noxor asked this question in Actions
Discussion options

You must be logged in to vote

Hi @noxor ,

To get the github context element, please check the json body firstly and follow the structure for your code. For instance, my ‘on: push’ event github context as below:

commits body has only one element which highlighted with {}, you can get the message from ${{ github.event.commits[0].message }}.

And there’s a ‘head_commit’ element, you can get the head commit(last) message from 

${{ github.event.head_commit.message }} as well.

If the body has mutliple elements like below array structure(fake just for example), you can use {{ github.event.commits[0].message }} for message 1, and {{ github.event.commits[1].message }}  for message 2.

{
....
"commits": [
      {
        "m…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants