# Extract data from each element of an array (for train departures board)

**URL:** <https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895>\
**Category:** General\
**Created:** [2 March 2021 13:53 UTC](https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895 "2021-03-02T13:53:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 March 2021 13:53 UTC](https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895/1 "2021-03-02T13:53:53Z")

</div>

Using the [realtimetrains.co.uk](http://realtimetrains.co.uk) API I can get a JSON formatted list of the next 50 (or less) trains to stop at / pass my local station.

So msg.payload.services is an array containing various fields of interest, eg  
msg.payload.services[n].locationDetail.origin[0].description (From Birmingham)  
msg.payload.services[n].locationDetail.destination[0].description (To Liverpool Lime Street)  
msg.payload.services[n].locationDetail.gbttBookedDeparture (Due departure time)  
msg.payload.services[n].locationDetail.realtimeDeparture (Expected departure time)  
etc.

What is the best way to extract those data from the array and display them on the dashboard as a departures board?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 March 2021 09:17 UTC](https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895/2 "2021-03-04T09:17:54Z")

</div>

loop through `msg.payload.services` entries and generate an array of objects containing key/val properties you want displaying and send it to a `ui template` or a `ui table` node for display.

e.g. if you loop that data source and generate the below format & drop it into msg.payload

```auto
[
    {
        "From": "xxx",
        "To": "yyy",
        "Scheduled Time": "zzz",
    },
    {
        "From": "xxx",
        "To": "yyy",
        "Scheduled Time": "zzz",
    },
]

```

... then send it to the ui table - pretty much job done.

see [info](https://flows.nodered.org/node/node-red-node-ui-table) here and search the forum for ui-table (or ui\_table) (covered many times)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [11 March 2021 09:56 UTC](https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895/3 "2021-03-11T09:56:11Z")

</div>

Sorry for the delay responding. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 May 2021 09:57 UTC](https://discourse.nodered.org/t/extract-data-from-each-element-of-an-array-for-train-departures-board/41895/4 "2021-05-10T09:57:07Z")

</div>

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