# Array\_of\_index()

**URL:** <https://community.tulip.co/t/array-of-index/8179>\
**Category:** Support, Troubleshooting, & Help\
**Created:** [April 26, 2023, 11:53am UTC](https://community.tulip.co/t/array-of-index/8179 "2023-04-26T11:53:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youri.regnaud](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/youri.regnaud/32/2917_2.png) [@youri.regnaud](https://community.tulip.co/u/youri.regnaud)\
**Post date:** [April 26, 2023, 11:53am UTC](https://community.tulip.co/t/array-of-index/8179/1 "2023-04-26T11:53:57Z")

</div>

I have a variable of type array of object for which I want to find the index of an object according to 2 fields of the object which represents the unique key. With ARRAY\_OF\_INDEX I can do this operation with a unique key in a unique field, but not with a key composed of 2 fields. Any idea?

---

<div class="post-metadata">

**Author:** ![thorsten.langner](https://avatars.discourse-cdn.com/v4/letter/t/4bbf92/32.png) [@thorsten.langner](https://community.tulip.co/u/thorsten.langner)\
**Post date:** [April 26, 2023, 2:56pm UTC](https://community.tulip.co/t/array-of-index/8179/2 "2023-04-26T14:56:03Z")

</div>

Here is a Workaround for one key:

> [@How to update a value in an Array displayed via Table Widget](https://community.tulip.co/t/how-to-update-a-value-in-an-array-displayed-via-table-widget/8036/8):
>
> @Gary worth noting that this can be compressed into a single trigger action if you’d prefer to keep it tight

I guess its becoming tricky with two key fields since even the easyer operations are often not provided for objects / object-arrays.

---

<div class="post-metadata">

**Author:** ![freedman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/freedman/32/107_2.png) [@freedman](https://community.tulip.co/u/freedman)\
**Post date:** [April 26, 2023, 3:28pm UTC](https://community.tulip.co/t/array-of-index/8179/3 "2023-04-26T15:28:21Z")

</div>

@youri.regnaud I’m thinking about how to approach this and what I would like to do is concatenate the keys and store the result into an array. I don’t think this is possible with the expression editor. Open to creative solutions, here, but if it were me I would make a custom widget that parses it and spits out the information I want. Sometimes it’s just easier to make a little widget that does what I want!

---

<div class="post-metadata">

**Author:** ![tony.wang](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@tony.wang](https://community.tulip.co/u/tony.wang)\
**Post date:** [April 26, 2023, 3:37pm UTC](https://community.tulip.co/t/array-of-index/8179/4 "2023-04-26T15:37:07Z")

</div>

customer widget will be a good way for your requirements, Here is the JS code you can refer to:

sampleArray is your input:  
var sampleArray = [  
{“id”: 1, “name”: “tony”,“age”:11},  
{“id”: 2, “name”: “tony1”,“age”:22},  
{“id”: 3, “name”: “tony2”,“age”:33},  
{“id”: 4, “name”: “tony3”,“age”:44}  
];

```
//getting the object by its id and name
var output = sampleArray.find(object => object.id === 3 && object.name === "tony2" );

```

Maybe one row code in Customer Widget 😀

---

<div class="post-metadata">

**Author:** ![k.ober](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/k.ober/32/6330_2.png) [@k.ober](https://community.tulip.co/u/k.ober)\
**Post date:** [April 26, 2023, 5:55pm UTC](https://community.tulip.co/t/array-of-index/8179/5 "2023-04-26T17:55:28Z")

</div>

Hmm, super interesting. For the sake of the thought experiment, trying to do this without a widget…

```auto
 col1 | col2
=============
a | x
b | y
c | z

1. [expression] map_to_text_list(col1), [a,b,c]
2. [expression] map_to_text_list(col2), [x,y,z]
3. [arrays] get length of either (assuming equal), col1_size=3
4. [arrays] join to string, col1_string = a,b,c
5.0[expression] set i to 0
5.1[arrays] get from index in array, col2[i] = col2_var = x
6. [expression] substitute(col1_string, ',', col2_var)
7. [etc] Repeat steps 5 and 6, i++, for col1_size times --> now you have col1_string=(axbycz)
8. [expression] find("by", col1_string) = target_index = 2
9. [arrays] get from index in array(my_full_array, target_index)

```

This method relies on making the values into pairs, i.e. ` 'col1[0]' + 'col2[0]' = [ax]` and then searching for the pair you want. However, I’m not sure there is a way to do this without manually making _n_ functions for a list of length _n_.

Widgets seem to probably be your best path here, unless I’m missing something.  
(or, I guess, just display the list as an Interactive Table and filter the columns, but then you need to force a user to click the table)

**edit:** as is tradition, found a similar method on SO, linked [here](https://stackoverflow.com/questions/60031974/combine-two-arrays-as-pairs):

```auto
let a = [1,2,3,4,5]
let b = [6,7,8,9,10]
let combine = a.map((e, i) => [e, b[i]]);
console.log(combine);

```

now `combine` is `([1,6], [2,7], ...)`

---

<div class="post-metadata">

**Author:** ![youri.regnaud](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/youri.regnaud/32/2917_2.png) [@youri.regnaud](https://community.tulip.co/u/youri.regnaud)\
**Post date:** [April 26, 2023, 6:56pm UTC](https://community.tulip.co/t/array-of-index/8179/6 "2023-04-26T18:56:24Z")

</div>

Thanks for your feedback. This is a nice proof that additional expressions for handling array of objects would be useful. Custom expression editor can be also an idea after custom widget
