# Search inside an object of arrays

**URL:** <https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916>\
**Category:** General\
**Created:** [30 July 2020 09:39 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916 "2020-07-30T09:39:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 09:39 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/1 "2020-07-30T09:39:02Z")

</div>

Hi , i am having problem searching a specific string inside an object of arrays, i have tried the node of viseo for searching an object with the result "Unfound Object". Also i have tried with two for loops searching the whole object and i constantly got "Can not read property 0 of undefined", then i searched the forum and i found 2 solution the one with json command match which got me an answer "undefined", and onw using wildcards with the same answer as before.! ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6200505631e8c1530cd9dcd63dac86661401e349.png)  
this is my object located at msg.dbase and the string i want to find is inside msg.disease. As a result i want the key number of the object, i don't care for the array key. Thank you in advance for your time!

---

<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:** [30 July 2020 09:56 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/2 "2020-07-30T09:56:17Z")

</div>

you could use a function node, call `var myFlatDB = msg.dbase.flat()` then use `msg.payload = myFlatDB.includes('what i am looking for')`;

NOTE: this will only state true or false as to finding an exact match.

If you need to search partial or case in-sensitive and/or get the x/y index positions of the found item, then you will need to loop through each row (array) and then loop through each sub array & use regex or `.includes()` on each value

---

<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:** [30 July 2020 10:07 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/3 "2020-07-30T10:07:22Z")

</div>

Here is an example

```auto
[{"id":"e7d8edec.a0fdd","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"8e2174d6.8ba838","type":"inject","z":"e7d8edec.a0fdd","name":"","props":[{"p":"dbase","v":"{\"0\":[\"test1\",\"test2\",\"test3\",\"test4\"],\"1\":[\"test5\"],\"2\":[\"test6\"],\"3\":[\"tesat7\"]}","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":160,"wires":[["c54e814b.1a87"]]},{"id":"cc78d184.6d6a58","type":"debug","z":"e7d8edec.a0fdd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":160,"wires":[]},{"id":"c54e814b.1a87","type":"function","z":"e7d8edec.a0fdd","name":"","func":"msg.disease = \"test2\";\n\nfor (var key in msg.dbase) {\n if(msg.dbase[key].includes(msg.disease)){\n return {\"key\":key};\n }\n}\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":160,"wires":[["cc78d184.6d6a58"]]}]

```

As Steve said this will only work for exact match.

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 10:07 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/4 "2020-07-30T10:07:42Z")

</div>

> [@Steve-Mcl](#):
>
> `var myFlatDB = msg.dbase.flat()` then use `msg.payload = myFlatDB.includes('what i am looking for')`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7dd2178c394aadc91a1de35021ac2bed80f96827.png)  
again the same thing as when i tried to loop through each row and sub array

---

<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:** [30 July 2020 10:11 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/5 "2020-07-30T10:11:32Z")

</div>

what is in `msg.dbase`? My guess is nothing (hence the undefined error)

put a debug set to show complete message BEFORE the function - check `msg.dbase` is an array.

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 10:15 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/6 "2020-07-30T10:15:44Z")

</div>

> [@Steve-Mcl](#):
>
> messag

Yes its nothing but i created it with this function

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

---

<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:** [30 July 2020 10:17 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/7 "2020-07-30T10:17:55Z")

</div>

Ahh just spotted - its and object with properties `0` and `1` which are arrays.

So flat wont work as expected (i think).

so you will need to get the keys `var keys = Object.keys(msg.dbase);` then loop through the array of keys and then search each array.

I can help if you knock up a demo flow with real data being injected (i.e. simulate your database using an inject)

1. copy the `msg.dbase` data using the "Copy Value" button on the debug window
2. paste the copied value into a change node that sets `msg.dbase` to the value you copied
3. connect that to the function

You should end up with...

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

then export the partial flow and paste in a reply...  
`````  
`paste flow like this`  
`````

---

<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:** [30 July 2020 10:22 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/8 "2020-07-30T10:22:32Z")

</div>

> [@Bernnt](#):
>
> but i created it

Ah ha - YOU create the data & you have created a format difficult to search.

In that case - easy - dont create a difficult format of object with array props inside!!! - then finding is MUCH easier.

- set `msg.dbase = []` instead. Then your data will be an array.
- next, add the conditions using `[...conditions]` (so you are adding ITEMS instead of adding sub-ARRAYS)

If you can generate dummy data for `msg.payload.search_results` I can show you how

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 10:38 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/9 "2020-07-30T10:38:56Z")

</div>

my initial data is an xml file that i only keep the subfolder studies[i].conditions.condition and when i put conditions inside [..] it understands it as a variable that is not defined. i change the type of msg.dbase from obj to array but i cannot add items instead of sub-arrays

---

<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:** [30 July 2020 10:51 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/10 "2020-07-30T10:51:03Z")

</div>

You can make a dummy flow with data inside (so I can simulate your situation) and I'll help - or - you can keep trying with the tips I've given you.

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 11:00 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/11 "2020-07-30T11:00:06Z")

</div>

where file i put the directory of my xml file which i cannot send throw this message box, but i downloaded from here: [https://clinicaltrials.gov/ct2/results?cond=&term=&cntry=&state=&city=&dist=](https://clinicaltrials.gov/ct2/results?cond=&term=&cntry=&state=&city=&dist=)  
with the option xml and All Available Columns  
thank you very much for your time!  
i keep trying with the array and sub array format that i understand!

```auto
[{"id":"5921d952.b44428","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ab957ec7.29539","type":"inject","z":"5921d952.b44428","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"Init","payloadType":"str","x":180,"y":240,"wires":[["e6ac2c8a.50e338"]]},{"id":"e6ac2c8a.50e338","type":"file in","z":"5921d952.b44428","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":310,"y":240,"wires":[["7b2344d.1aaf73c"]]},{"id":"7b2344d.1aaf73c","type":"xml","z":"5921d952.b44428","name":"","property":"payload","attr":"","chr":"","x":430,"y":240,"wires":[["5cfb50e6.458ac8"]]},{"id":"5cfb50e6.458ac8","type":"function","z":"5921d952.b44428","name":"","func":"msg.dbase = [];\nvar len = msg.payload.search_results.study.length;\nfor(var i=0;i<5;i++){\n msg.dbase[i] = msg.payload.search_results.study[i].conditions[0].condition;\n}\nmsg.payload = msg.dbase[0];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":240,"wires":[["f27dd386.2468b8"]]},{"id":"f27dd386.2468b8","type":"debug","z":"5921d952.b44428","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"dbase","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":240,"wires":[]}]

```

---

<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:** [30 July 2020 14:08 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/12 "2020-07-30T14:08:25Z")

</div>

Here you go ...

 ![KIPMbe8lbK](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83f9b39d13b6d8bfbb3722b730f92b9adf78d611.gif)

```auto
[{"id":"81d62991.c28128","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"Init","payloadType":"str","x":150,"y":220,"wires":[["5c782e34.536cd"]]},{"id":"5c782e34.536cd","type":"file in","z":"c479d7d3.fce8d8","name":"","filename":"c:/temp/SearchResults.xml","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":350,"y":220,"wires":[["408f6d3b.017944"]]},{"id":"408f6d3b.017944","type":"xml","z":"c479d7d3.fce8d8","name":"","property":"payload","attr":"","chr":"","x":560,"y":220,"wires":[["5c6ece81.d698f","9f6eba98.0d1798"]]},{"id":"5c6ece81.d698f","type":"function","z":"c479d7d3.fce8d8","name":"","func":"var dbase = [];\nvar len = msg.payload.search_results.study.length;\nfor(var i=0;i<len;i++){\n let data = msg.payload.search_results.study[i].conditions[0].condition;\n dbase.push(...data);\n}\nmsg.payload = dbase;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":280,"wires":[["5ef24e86.83332"]]},{"id":"50ca8499.0587fc","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":280,"wires":[]},{"id":"9f6eba98.0d1798","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":220,"wires":[]},{"id":"5ef24e86.83332","type":"change","z":"c479d7d3.fce8d8","name":"","rules":[{"t":"set","p":"conditions","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":280,"wires":[["50ca8499.0587fc"]]},{"id":"ce4e8cef.b3c4a","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Anesthesia","payloadType":"str","x":160,"y":360,"wires":[["a328617b.422e"]]},{"id":"51739fff.279b6","type":"comment","z":"c479d7d3.fce8d8","name":"1. Load XML data, make flat array, store it in flow.conditions","info":"","x":310,"y":180,"wires":[]},{"id":"25e1145d.1ca0dc","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Food Habits","payloadType":"str","x":170,"y":400,"wires":[["a328617b.422e"]]},{"id":"3664026f.ed7f9e","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"_wont_find_me_","payloadType":"str","x":180,"y":480,"wires":[["a328617b.422e"]]},{"id":"744fa604.4422c8","type":"function","z":"c479d7d3.fce8d8","name":"exact search (exists true/false)","func":"var findWhat = msg.payload;\nvar conditions = msg.conditions;\nmsg.payload = conditions.includes(findWhat);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":360,"wires":[["d11e148d.d87bb8"]]},{"id":"a328617b.422e","type":"change","z":"c479d7d3.fce8d8","name":"","rules":[{"t":"set","p":"conditions","pt":"msg","to":"conditions","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":360,"wires":[["744fa604.4422c8","d5a4ad29.38883","fbbe6b53.c33038","75b9828c.2c14bc","607e9988.3398c8"]]},{"id":"d5a4ad29.38883","type":"function","z":"c479d7d3.fce8d8","name":"partial search (exists true/false)","func":"var findWhat = msg.payload;\nvar conditions = msg.conditions;\nmsg.payload = conditions.some(e => e.includes(findWhat));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":420,"wires":[["72e94dd8.cfab74"]]},{"id":"fbbe6b53.c33038","type":"function","z":"c479d7d3.fce8d8","name":"find partial (returns found item)","func":"var findWhat = msg.payload;\nvar conditions = msg.conditions;\nmsg.payload = conditions.find(e => e.includes(findWhat));\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":540,"wires":[["2dc6d0cf.02dbb"]]},{"id":"d11e148d.d87bb8","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":360,"wires":[]},{"id":"72e94dd8.cfab74","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":420,"wires":[]},{"id":"2dc6d0cf.02dbb","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":540,"wires":[]},{"id":"5df2abd6.e1bb94","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Quality Imp","payloadType":"str","x":170,"y":520,"wires":[["a328617b.422e"]]},{"id":"75b9828c.2c14bc","type":"function","z":"c479d7d3.fce8d8","name":"find partial (returns found item) (case insensitive)","func":"var findWhat = msg.payload.toLowerCase();\nvar conditions = msg.conditions;\nmsg.payload = conditions.find(e => e.toLowerCase().includes(findWhat));\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":600,"wires":[["75c6f58f.475a5c"]]},{"id":"607e9988.3398c8","type":"function","z":"c479d7d3.fce8d8","name":"partial search (exists true/false) (case insensitive)","func":"var findWhat = msg.payload.toLowerCase();\nvar conditions = msg.conditions;\nmsg.payload = conditions.some(e => e.toLowerCase().includes(findWhat));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":480,"wires":[["c8cd13ba.4b378"]]},{"id":"c8cd13ba.4b378","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":480,"wires":[]},{"id":"75c6f58f.475a5c","type":"debug","z":"c479d7d3.fce8d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":600,"wires":[]},{"id":"463f9ee6.77792","type":"comment","z":"c479d7d3.fce8d8","name":"2. Perform the search","info":"","x":180,"y":320,"wires":[]},{"id":"f4af84b8.e507b8","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"fOOd HaBiTs","payloadType":"str","x":170,"y":440,"wires":[["a328617b.422e"]]},{"id":"e3c813b1.cf5e7","type":"comment","z":"c479d7d3.fce8d8","name":"FIRST - change the file path to your XML file","info":"","x":470,"y":100,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 14:43 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/13 "2020-07-30T14:43:40Z")

</div>

thank you very much but even i took your flow exactly the same and i only changed the directory of the xml i get this error  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7aadc916646ccc1455b9e48110f917aa966c932.png)  
it probably because the dbase doesn't iterate, but thank again for your help

---

<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:** [30 July 2020 14:58 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/14 "2020-07-30T14:58:29Z")

</div>

> [@Bernnt](#):
>
> i took your flow exactly the same and i only changed the directory of the xml i get this error

did you press the top inject first?

Look in context you should see the data...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76e3a81e225f315f11fdbf018e7821ae93a67cd3.png)

The fisrt inject loads the XML and converts it to a flat array (as I explained 3 posts ago, and as per my flow in the previous post) - then stores the flat array in flow context (as per picture above)

If you dont have that data then YES, `includes` will not be possible due to having no data to look through.

If in doubt - add a debug to EVERY node, press the inject, see where it fails.

EDIT...  
Also, as you can see from my animation - it definitely works.

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 15:03 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/15 "2020-07-30T15:03:15Z")

</div>

i copied exactly your flow, the database creation and insertion in the flow hapen as soon as i deploy, and i have the error, TypeError: data is not iterable (cannot read property undefined) also i don't understand how it enters the flow context in this code  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6cc0eae95aef98e2bb522ba32db448936fa51b44.png)  
yes this is the strange thing, i copied exactly your code and didn't change anything(exept the xml path)

---

<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:** [30 July 2020 15:06 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/16 "2020-07-30T15:06:32Z")

</div>

> [@Bernnt](#):
>
> i copied exactly your code

Did you not simply import the flow?

* * *

Please answer the questions...

- did you operate the first inject?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61e92a439ad1ad28e01e7b86e662c3a9719c01ad.png)  
this is required to populate the context store

- did you check context like i asked? Is there data in it?

- which inject causes the error - top one or bottom one?

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 15:14 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/17 "2020-07-30T15:14:00Z")

</div>

yes i imported it, yes i push the inject with Init in the label. The init node causes the error, i dont know how to check for the flow context but the error happens at the function node. i tried removing the three dots and the array showed as did before but with the three dots at the push command(dbase.push(...data))it shows the error that i mention above

---

<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:** [30 July 2020 15:17 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/18 "2020-07-30T15:17:24Z")

</div>

> [@Bernnt](#):
>
> but with the three dots at the push command(dbase.push(...data))it shows the error

What version of nodejs are you using?  
What version of node-red are you using?

the spread operator `...` has been available since node version 5.

it should not cause you an error unless the data format of the XML is different.

---

<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:** [30 July 2020 15:19 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/19 "2020-07-30T15:19:02Z")

</div>

> [@Bernnt](#):
>
> i dont know how to check for the flow context

I literally posted a screen shot showing you how.

 ![XuR2XqmrrB](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a841a44c8d06aa9b75e1c5790ccccce3f7613d2.gif)

---

<div class="post-metadata">

**Author:** ![Bernnt](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@Bernnt](https://discourse.nodered.org/u/Bernnt)\
**Post date:** [30 July 2020 15:23 UTC](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916/20 "2020-07-30T15:23:20Z")

</div>

my context data is like before, without changing anything to your flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce7e86a28a2bfc635f0fa59e573be207cbc17ea4.png)  
my node version is 14.7.0

[Next page](https://discourse.nodered.org/t/search-inside-an-object-of-arrays/30916.md?page=2)
