Delete part of an object in Context


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 ?



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

[{"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"]]}]

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.

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).

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

1 Like


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


Thanks will give that a try after the one from E1Cid


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("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 !!)

Any other ideas ??


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

You da man thanks Steve !!!

Once again you come through



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

[{"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

1 Like

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


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