# Simple array variable -\> array of objects

**URL:** <https://community.weweb.io/t/simple-array-variable-array-of-objects/7389>\
**Category:** How do I?\
**Tags:** formulas, binding\
**Created:** [March 2, 2024, 10:45pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389 "2024-03-02T22:45:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gduteaud](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gduteaud](https://community.weweb.io/u/gduteaud)\
**Post date:** [March 2, 2024, 10:45pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/1 "2024-03-02T22:45:14Z")

</div>

I have a “newLabels” array variable that I use to store the uuids of selected items from a multi-select element.

Since this reflects a many-to-many relationship in my database (Supabase), I’m now trying to use this array as part of a batch insert on a junction table i.e. I want to insert as many records as there are items in the array, each with key1 : (same value for all records) and key2: (array item value).

I know the binding syntax for this to work needs to be an array of objects but I can’t figure out how to turn my simple array variable into an array of objects where key 1 has the same value for all items and key 2 has the value of the corresponding item in the array variable.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/0/0b7520cf9925c75a5c4b9d2427a6144ac199b303.png)

The AI formula helper is not helpful, only producing formulas that don’t work.

I think this is basically the same question as in this thread [Create multiple objects from multi-select](https://community.weweb.io/t/create-multiple-objects-from-multi-select/2926) except I would like a no-code solution. The last reply in that thread indicates that should be possible but doesn’t elaborate on how.

Any help would be appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [March 8, 2024, 2:10pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/2 "2024-03-08T14:10:33Z")

</div>

Hi @gduteaud 👋

The only idea that comes to mind right now is to use a [for loop action in a workflow](https://docs.weweb.io/workflows/actions/iterator.html) through the array and create a new one with the proper formatting.

Does that help?

---

<div class="post-metadata">

**Author:** ![gduteaud](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gduteaud](https://community.weweb.io/u/gduteaud)\
**Post date:** [March 8, 2024, 3:14pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/3 "2024-03-08T15:14:14Z")

</div>

Thank you Joyce! That makes sense but it turns out what I wanted to do is trivial to implement in JS so that’s what I did.

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [March 8, 2024, 4:09pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/4 "2024-03-08T16:09:11Z")

</div>

Nice! Would you mind sharing the solution for others who may read this in the future?

---

<div class="post-metadata">

**Author:** ![kanepaamauloa](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kanepaamauloa/32/8944_2.png) [@kanepaamauloa](https://community.weweb.io/u/kanepaamauloa)\
**Post date:** [May 15, 2024, 1:24pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/5 "2024-05-15T13:24:54Z")

</div>

Hi @gduteaud,

I’m facing a similar challenge right now. I’d appreciate if you could share?

I’m trying to use the formulas provided by WeWeb, but none of them seem to apply.

---

<div class="post-metadata">

**Author:** ![kanepaamauloa](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kanepaamauloa/32/8944_2.png) [@kanepaamauloa](https://community.weweb.io/u/kanepaamauloa)\
**Post date:** [May 15, 2024, 1:37pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/6 "2024-05-15T13:37:04Z")

</div>

Figured it out!

I didn’t know you could write JavaScript into the formula field!

Here’s what I put into the formula field:

```auto
"MultiselectCurrentSelection".map(function(val){ return {"key1": globalContext.pageParameters['variable'], "key2": val};})

```

The shortcut syntax would be use a fat arrow `val => ...` instead of `function(val){...}`, but the formula editor gets in the way.

---

<div class="post-metadata">

**Author:** ![gduteaud](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@gduteaud](https://community.weweb.io/u/gduteaud)\
**Post date:** [May 15, 2024, 3:02pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/7 "2024-05-15T15:02:10Z")

</div>

Yeah my solution was also to use JS. FYI on the top left of the formula editor you can change it to an actual JS editor, that should solve your arrow function issue!

---

<div class="post-metadata">

**Author:** ![kanepaamauloa](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kanepaamauloa/32/8944_2.png) [@kanepaamauloa](https://community.weweb.io/u/kanepaamauloa)\
**Post date:** [May 16, 2024, 2:21pm UTC](https://community.weweb.io/t/simple-array-variable-array-of-objects/7389/8 "2024-05-16T14:21:02Z")

</div>

WOW! Thanks @gduteaud! I’m still learning the WeWeb interface. That’s amazing!

Pretty stoked that you can get into the code if you need to. Good job WeWeb!
