# Delete part of an object in Context

**URL:** <https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371>\
**Category:** General\
**Created:** [22 September 2021 03:53 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371 "2021-09-22T03:53:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [22 September 2021 03:53 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/1 "2021-09-22T03:53:23Z")

</div>

Guys,

As my battery project has evolved i have evolved the name of objects and their properties.

Is there a way to delete single parts of an object to remove any confusion ? Obviously i can delete the whole object if needed - but does not seem to be a way on the side panel to delete the values in the object - for example in the image below - i no longer use DesiredChargeRate , but instead use DesiredRate - so can i delete the subobject of DesiredChargeRate ?

Craig

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

---

<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:** [22 September 2021 06:46 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/2 "2021-09-22T06:46:38Z")

</div>

Not possible from side bar, But you could create a small flow to do so while testing  
eg.

```auto
[{"id":"3430a09a.69749","type":"function","z":"b779de97.b1b46","name":"","func":"let obj = flow.get(\"Battery\");\ndelete obj.DesiredChargeRate;\nflow.set(\"restart\", obj);// not needed as obj is now refering to flow var restart\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":3920,"wires":[[]]},{"id":"8d5915e4.d3505","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":3900,"wires":[["3430a09a.69749"]]}]

```

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 September 2021 13:20 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/3 "2021-09-22T13:20:00Z")

</div>

If I understood correctly you want to delete variable names that were used in the past and are no longer in use ( but appear in the context tab ) ? If that is the case then You can use the delete icon in the context tab in the sidebar.

 ![a3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8472a3850e662726a03b1740a535e5d1b4904ee.png)

PS: I guess I got the point. You want to delete only some properties of objects stored in the context. If that is the case it is just a matter of saving again the object without those unwanted properties (that are anyway no longer used).

---

<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:** [22 September 2021 13:40 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/4 "2021-09-22T13:40:53Z")

</div>

> [@craigcurtin](#):
>
> can i delete the subobject of DesiredChargeRate ?

another approach (_which i read in another post but dont remember when_) is to set to undefined.  
`flow.set("Battery[SBP-Right].DesiredChargeRate", undefined);`

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [22 September 2021 21:35 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/5 "2021-09-22T21:35:06Z")

</div>

Andrei,

That does not work for part of an object - i can delete the whole object but not the parts (or as you say standard Variables etc

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [22 September 2021 21:35 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/6 "2021-09-22T21:35:34Z")

</div>

Thanks will give that a try after the one from E1Cid

Craig

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [23 September 2021 00:24 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/7 "2021-09-23T00:24:40Z")

</div>

> [@UnborN](#):
>
> flow.set("Battery[SBP-Right].DesiredChargeRate", undefined);

OK tried both e1Cid and Unborns options (they are global rather than flow objects) so changed as appropriate.

Did not work - made no changes when i ran it

The commented out parts are the first attempt which i ran by itself and then the 2nd one is Unborns idea

//let obj = global.get("Battery");  
//delete obj.SBP-Right.DesiredChargeRate;  
[//global.set](https://global.set)("Battery", obj);// not needed as obj is now refering to flow var restart  
global.set("Battery[SBP-Right].DesiredChargeRate", undefined);  
return msg;

still stubbornly sitting there (yes i have refreshed !!)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c44e1ccbfdbe09264ec479003b8a64d71981810a.png)

Any other ideas ??

Craig

---

<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:** [23 September 2021 00:37 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/8 "2021-09-23T00:37:21Z")

</div>

```auto
let obj = global.get("Battery");
delete obj["SBP-Right"].DesiredChargeRate;
global.set("Battery", obj);

```

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [23 September 2021 01:39 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/9 "2021-09-23T01:39:25Z")

</div>

You da man thanks Steve !!!

Once again you come through

regards

Craig

---

<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:** [23 September 2021 03:08 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/10 "2021-09-23T03:08:13Z")

</div>

my bad, i should have tested it more thoroughly ..  
it seems the `[]` syntax doesnt work when setting Context for **Objects**.  
the code should have been  
`global.set("Battery.SBP-Right.DesiredChargeRate", undefined);`

which was a bit confusing because in javascript when you have the special dash / minus `-` character in the property name you need to use the `[]` syntax so i presumed that it would work.

**Test Flow**

```auto
[{"id":"75f5e3b9b7132219","type":"inject","z":"4895ea10b4ee9ead","name":"set","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":270,"y":300,"wires":[["41b4634b728fe281"]]},{"id":"41b4634b728fe281","type":"function","z":"4895ea10b4ee9ead","name":"","func":"global.set(\"test.SBP-Right.DesiredChargeRate\", 123);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":300,"wires":[[]]},{"id":"7b6697bcbf49b32e","type":"inject","z":"4895ea10b4ee9ead","name":"del","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":270,"y":360,"wires":[["b30bc3a7fc1eb202"]]},{"id":"b30bc3a7fc1eb202","type":"function","z":"4895ea10b4ee9ead","name":"","func":"global.set(\"test.SBP-Right.DesiredChargeRate\", undefined);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":360,"wires":[[]]}]

```

Found the post i read about setting to `undefined`. it was [here](https://discourse.nodered.org/t/how-to-delete-a-flow-variable-from-a-function-node/19731/2)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 September 2021 09:04 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/11 "2021-09-24T09:04:05Z")

</div>

Good one thanks mate - thanks for hanging in there !!

Craig

---

<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:** [8 October 2021 09:04 UTC](https://discourse.nodered.org/t/delete-part-of-an-object-in-context/51371/12 "2021-10-08T09:04:54Z")

</div>

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