# Search Arrays for Related Data

**URL:** <https://discourse.nodered.org/t/search-arrays-for-related-data/57967>\
**Category:** General\
**Created:** [8 February 2022 04:12 UTC](https://discourse.nodered.org/t/search-arrays-for-related-data/57967 "2022-02-08T04:12:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikewoodld](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikewoodld/32/26822_2.png) [@mikewoodld](https://discourse.nodered.org/u/mikewoodld)\
**Post date:** [8 February 2022 04:12 UTC](https://discourse.nodered.org/t/search-arrays-for-related-data/57967/1 "2022-02-08T04:12:48Z")

</div>

Scenario: I have a google sheet that has two columns, phone number and name:

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

I want to be able to lookup the name based on the phone number.

Using a google sheets node, I'm able to grab the data as an array:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6dc05332d4218f351244bc9881422edf7302bfd8.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c49d7de6736f8e2b27596ab09bcb5393d2d479a.png)

Now, I'd like to be able to search through all of the sub-arrays using a phone number and find the matching name that corresponds to it.

* * *

To say it another way, I already have the phone number (in this case an incoming text from Twilio) and I want to be able to look up the name in this sheet using that phone number regardless of its position in the sheet. (to eventually use it in a customized response - that part I can handle, I'm just stuck on how to search through and find the match.)

Any ideas on the best way to accomplish this?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 February 2022 04:21 UTC](https://discourse.nodered.org/t/search-arrays-for-related-data/57967/2 "2022-02-08T04:21:54Z")

</div>

You can use a **Function node** using the Javascript [find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) method on the array

```auto
msg.payload = msg.payload.find( el => el[0] == "12222222" )
return msg;

```

---

<div class="post-metadata">

**Author:** ![mikewoodld](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikewoodld/32/26822_2.png) [@mikewoodld](https://discourse.nodered.org/u/mikewoodld)\
**Post date:** [8 February 2022 04:22 UTC](https://discourse.nodered.org/t/search-arrays-for-related-data/57967/3 "2022-02-08T04:22:55Z")

</div>

> [@UnborN](#):
>
> ```auto
> msg.payload = msg.payload.find( el => el[0] == "12222222" )
> return msg;
> 
> ```

This worked perfectly. Thank you so much!

---

<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:** [22 February 2022 04:23 UTC](https://discourse.nodered.org/t/search-arrays-for-related-data/57967/4 "2022-02-22T04:23:52Z")

</div>

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