Getting last array item automatically?

Hi! I’m attempting to automatically get the last item of a nested JSON array whether it has one or many. Below is an example of my data flow, the focus would be “Collections” => “Category” => Last Item (category:2). I’m sorry if it doesn’t make sense, I will try my best to clarify if there’s any confusion. Thank in advance! :smiley:

{
  "neighborhood": {
    "id": 260,
    "name": "WASHINGTON HEIGHTS"
  },`
  "city": {
    "id": 3,
    "name": "Manhattan"
  },
  "collections": [
    {
      "id": 22,
      "name": "New Yorker",
      "description": "-",
      "category": 1,
      "yield_boost": 1.2
    },
    {
      "id": 24,
      "name": "New Yorker Plus",
      "description": "-",
      "category": 2,
      "yield_boost": 1.2
    },
  ]
},


## Information on your n8n setup
- **n8n version: 0.193.5**
- **Running n8n via npm**

Yes you can do this with collections[collections.length-1]

Thank you for the response.
How would I apply that on through expression or a function?

Second node is what you would need.

1 Like

Amazing thank you! Great solution, I appreciate the help!

1 Like