# How to filter a result from a resquest

**URL:** <https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357>\
**Category:** General\
**Created:** [9 March 2021 17:50 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357 "2021-03-09T17:50:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndz](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@ndz](https://discourse.nodered.org/u/ndz)\
**Post date:** [9 March 2021 17:50 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/1 "2021-03-09T17:50:39Z")

</div>

I have a request that returns basically that

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8870f2acd97696d125d545d4575a7791ae3b551.png)

inside of each item theres is an object that has a "dataAbertura" field, a string

im trying to filter these results with that function, but its not working

msg.payload.value.data.filter(e =\> e.dataAbertura.startsWith('2021-03-08'))

can somebody tells me whats wrong with that and how could i do it?

ps: sorry for my bad english

---

<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:** [9 March 2021 17:58 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/2 "2021-03-09T17:58:40Z")

</div>

Without seeing the data item or your full function it is almost impossible to say.

Do you assign the result of the filter function to msg.payload? Do you return the msg at the end of the function? Is dataAbertura a string? Does the data array contain objects & Is dataAbertura a parent property?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 March 2021 18:03 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/3 "2021-03-09T18:03:57Z")

</div>

Click on the array contents to expand one or more so we can see what is there.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 March 2021 18:14 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/4 "2021-03-09T18:14:19Z")

</div>

From the info supplied the JSONata expression used in a change node to filter on dataAbertura  
with dates containing the string '2021-03-08', would be

```auto
payload.value.data[$contains($.dataAbertura, "2021-03-08")]	

```

But untested as you supplied no data

---

<div class="post-metadata">

**Author:** ![ndz](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@ndz](https://discourse.nodered.org/u/ndz)\
**Post date:** [9 March 2021 18:17 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/5 "2021-03-09T18:17:16Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad9677cb507a663bccef5c4abc867fd84bd806ce.png)

its an object like that one that contains a lot of fields, one of these fields its

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c11393fd2434bf8a13d02463b8e7bda518c69c93.png)

and the complete function im using its

msg.payload.filter(e =\> e.dataAbertura.startsWith('2021-03-08'))

return msg;

with a debug node on the end

i cannot show u guys the entire object but it is a lot of fields like that "id" one

---

<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:** [9 March 2021 18:19 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/6 "2021-03-09T18:19:14Z")

</div>

Try...

```auto
msg.payload = msg.payload.value.data.filter(e => e.dataAbertura.startsWith('2021-03-08'))
return msg;

```

---

<div class="post-metadata">

**Author:** ![ndz](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@ndz](https://discourse.nodered.org/u/ndz)\
**Post date:** [9 March 2021 18:21 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/7 "2021-03-09T18:21:01Z")

</div>

it works !!

im sorry if this question was silly guys im kinda lost in node red yet, thanks a lot for your help

---

<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:** [23 March 2021 18:21 UTC](https://discourse.nodered.org/t/how-to-filter-a-result-from-a-resquest/42357/8 "2021-03-23T18:21:40Z")

</div>

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