# Insert property in object of weweb variable with javascript

**URL:** <https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698>\
**Category:** Ask us anything\
**Created:** [December 3, 2023, 10:53am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698 "2023-12-03T10:53:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![erbteilung](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@erbteilung](https://community.weweb.io/u/erbteilung)\
**Post date:** [December 3, 2023, 10:53am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/1 "2023-12-03T10:53:54Z")

</div>

In a workflow when I make a partial update and set the path to a new property (which is also in a new nested object) and it adds the object and the property.

I tried to do the same in javascript but failed:

variables[/\* fall\_updates \*/‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’][‘test’]=“test”;

Cannot read property of undefined.

After the object structure exists the javascript works but it does not create the objects and properties. So what is partial update doing under the hood?  
Something more complex?

---

<div class="post-metadata">

**Author:** ![Antiokh](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/antiokh/32/2794_2.png) [@Antiokh](https://community.weweb.io/u/Antiokh)\
**Post date:** [December 3, 2023, 1:09pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/2 "2023-12-03T13:09:56Z")

</div>

O, nice request. Where did you find the info about fall updates? Wanna read.

---

<div class="post-metadata">

**Author:** ![erbteilung](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@erbteilung](https://community.weweb.io/u/erbteilung)\
**Post date:** [December 3, 2023, 7:02pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/3 "2023-12-03T19:02:09Z")

</div>

Sorry for that I am creating a german app and fall in German means “Case”. It is a legal tech company… is just an example.

But wait until wednesday. I am very keen what they will present. The reworked the editor…

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [December 3, 2023, 7:12pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/4 "2023-12-03T19:12:05Z")

</div>

The new editor wont change the fact that what you’re doing goes against JS rules I guess.

The editor probably makes some sort of checks, or via some utility creates the missing properties of the object.

You can do something like in this stack overflow answer

> <https://stackoverflow.com/questions/17643965/how-to-automatically-add-properties-to-an-object-that-is-undefined>

---

<div class="post-metadata">

**Author:** ![raydeck](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raydeck/32/384_2.png) [@raydeck](https://community.weweb.io/u/raydeck)\
**Post date:** [December 4, 2023, 3:22am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/5 "2023-12-04T03:22:38Z")

</div>

I would stage:

```auto
// Step 1 - make sure fall exists and initialize to a blank object if not
if(!variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’]) variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’] = {}; 
// Step 2 - make sure the case exists andset it to a blank object if not
if(!variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’]) variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’] = {}
// Step 3 - update the test variable
variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’][‘test’]=“test”;

```

---

<div class="post-metadata">

**Author:** ![erbteilung](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@erbteilung](https://community.weweb.io/u/erbteilung)\
**Post date:** [December 4, 2023, 11:14am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/6 "2023-12-04T11:14:04Z")

</div>

Thank you so this is the way to go and the internal action will probably do it as well =)  
ok.

Just hoped to find a dynamic way where I can create properties of object nested in infinity levels. But to get this into a loop seems not so easy…

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [December 4, 2023, 3:06pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/7 "2023-12-04T15:06:08Z")

</div>

> [@erbteilung](#):
>
> So what is partial update doing under the hood?

I think we use the `set` method from lodash [Lodash Documentation](https://lodash.com/docs/#set)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [December 4, 2023, 3:07pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/8 "2023-12-04T15:07:11Z")

</div>

Thought so. Lodash instance is also accessible in the browser, isn’t it?

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [December 4, 2023, 3:11pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/9 "2023-12-04T15:11:55Z")

</div>

Yes but it includes only the methods we use. I don’t recommend to use them as we could remove lodash at some point and it will not work anymore.

![Capture d’écran 2023-12-04 à 16.09.08](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/2/23055bd127e724821801fa0042f6026820395ae3.png)

---

<div class="post-metadata">

**Author:** ![erbteilung](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@erbteilung](https://community.weweb.io/u/erbteilung)\
**Post date:** [December 4, 2023, 5:11pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/10 "2023-12-04T17:11:23Z")

</div>

Hmm… understood…

Than there is no save way to do the partial update with automatic object path creation with javascript?

---

<div class="post-metadata">

**Author:** ![raydeck](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raydeck/32/384_2.png) [@raydeck](https://community.weweb.io/u/raydeck)\
**Post date:** [December 5, 2023, 2:28am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/11 "2023-12-05T02:28:11Z")

</div>

You could use the npm plugin to add lodash that way. I haven’t confirmed this would work- only some npm packages do. I made a video on using the npm functionality with weweb:

[![](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/2/274694bad4c18004e017c755f2365abb48c52a98.jpeg "Making a QR Code with NPM Plugin in #Weweb\_io") ](https://www.youtube.com/watch?v=_g-pknCCbvk)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [December 5, 2023, 8:47am UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/12 "2023-12-05T08:47:37Z")

</div>

I’m not sure, because it might conflict with WeWeb’s lodash. I’ve tried to import supabase v2 like this.

---

<div class="post-metadata">

**Author:** ![raydeck](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/raydeck/32/384_2.png) [@raydeck](https://community.weweb.io/u/raydeck)\
**Post date:** [December 5, 2023, 4:58pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/13 "2023-12-05T16:58:18Z")

</div>

I checked - the lodash.set npm package will successfully import a window function called “set” that is the lodash set function. I looked at it in the editor - it does not appear to conflict with weweb internals.

---

<div class="post-metadata">

**Author:** ![erbteilung](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@erbteilung](https://community.weweb.io/u/erbteilung)\
**Post date:** [December 7, 2023, 7:05pm UTC](https://community.weweb.io/t/insert-property-in-object-of-weweb-variable-with-javascript/5698/14 "2023-12-07T19:05:11Z")

</div>

Thank you very much raydeck!  
I will go this route…
