# Filter a msg.payload

**URL:** <https://discourse.nodered.org/t/filter-a-msg-payload/51496>\
**Category:** Developing Nodes\
**Created:** [25 September 2021 05:13 UTC](https://discourse.nodered.org/t/filter-a-msg-payload/51496 "2021-09-25T05:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [25 September 2021 05:13 UTC](https://discourse.nodered.org/t/filter-a-msg-payload/51496/1 "2021-09-25T05:13:21Z")

</div>

Using the Unifi Node and I need to understand how to filter a msg.payload please, for example filter the last five alarms/alerts. Thanks in advance for any guidance...

So in the Unifi UI it has Admin Admin username log in from 1.1.1.1 5:06 pm 09/25/2021 so I would like to reproduce the last 5 alerts in the same format.

Example Output

[[{"\_id":"61319dae33f1aa1ff4a97c96","ip":"1.1.1.1","admin":"Admin[nameofuser]","site\_id":"5dd35c62e9d29101752c640d","is\_admin":true,"key":"EVT\_AD\_Login","subsystem":"","time":1630641582993,"datetime":"2021-09-03T03:59:42Z","msg":"Admin[nameofuser] log in from 1.1.1.1"},{"\_id":"61319dae33f1aa1ff4a97c95","ip":"1.1.1.1","admin":"Admin[nameofuser]","site\_id":"5dd35c62e9d29101752c640d","is\_admin":true,"key":"EVT\_AD\_Login","subsystem":"","time":1630641582891,"datetime":"2021-09-03T03:59:42Z","msg":"Admin[nameofuser] log in from 1.1.1.1"},{"\_id":"61319dae33f1aa1ff4a97c94","ip":"1.1.1.1","admin":"Admin[nameofuser]","site\_id":"5dd35c62e9d29101752c640d","is\_admin":true,"key":"EVT\_AD\_Login","subsystem":"","time":1630641582864,"datetime":"2021-09-03T03:59:42Z","msg":"Admin[nameofuser] log in from 1.1.1.1"},{"\_id":"61319d5a33f1aa1ff4a97c93","ip":"1.1.1.1","admin":"Admin[nameofuser]","site\_id":"5dd35c62e9d29101752c640d","is\_admin":true,"key":"EVT\_AD\_Login","...

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 September 2021 07:12 UTC](https://discourse.nodered.org/t/filter-a-msg-payload/51496/2 "2021-09-25T07:12:20Z")

</div>

It should be easy enough in a `function` node using the array 'length' and 'slice' methods. Get the count of array items, subtract 5 from it and slice the array using count-5

If you are unclear about the 'length; and 'slice' methods, take a look at  
[https://www.w3schools.com/jsref/jsref\_length\_array.asp](https://www.w3schools.com/jsref/jsref_length_array.asp)  
[https://www.w3schools.com/jsref/jsref\_slice\_array.asp](https://www.w3schools.com/jsref/jsref_slice_array.asp)

---

<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:** [24 November 2021 07:13 UTC](https://discourse.nodered.org/t/filter-a-msg-payload/51496/3 "2021-11-24T07:13:12Z")

</div>

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