# Advice on using hasOwnProperty

**URL:** <https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508>\
**Category:** General\
**Created:** [12 January 2024 10:52 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508 "2024-01-12T10:52:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)\
**Post date:** [12 January 2024 10:52 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/1 "2024-01-12T10:52:24Z")

</div>

Hello

I need to check if a payload property exists. The payload looks like this:

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

The path to that payload object is payload.data.dps["5"]

Sometimes element 5 is not present. How do I check if element 5 exists in this payload with hasOwnProperty?

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [12 January 2024 10:59 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/2 "2024-01-12T10:59:04Z")

</div>

Hi,

With:

```js
Object.prototype.hasOwnProperty.call(msg.payload.data.dps, "5");

```

---

<div class="post-metadata">

**Author:** ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)\
**Post date:** [12 January 2024 11:03 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/3 "2024-01-12T11:03:29Z")

</div>

Thank you!

---

<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:** [12 January 2024 11:58 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/4 "2024-01-12T11:58:36Z")

</div>

Or

```auto
msg.payload.data.dps.hasOwnProperty("5")

```

The difference being you can use nullish Coalescing optional chaining.

```auto
msg.payload?.data?.dps?.hasOwnProperty("5")

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 January 2024 17:44 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/5 "2024-01-12T17:44:29Z")

</div>

There is a reason to use the form that GogoVega has used. Can't remember the details but it is the safest way to do it.

However, there is a still newer method:

> **[Object.hasOwn() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)**
>
> The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property.
> If the property is inherited, or does not exist, the method returns false.

This is intended to replace `hasOwnProperty` and it should be safe to use directly. It correctly identifies properties set to `null` or `undefined` and it ignores properties inherited from the object prototype.

Note however that you must be using node.js v16.9.0 or above to use `hasOwn`.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [12 January 2024 17:47 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/6 "2024-01-12T17:47:16Z")

</div>

> [@TotallyInformation](#):
>
> Can't remember the details

Because of `Object.create()` - the risk is that property does not exist or has been rewritten.  
There are other more purist reasons but that's not my area

---

<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:** [12 January 2024 19:30 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/7 "2024-01-12T19:30:56Z")

</div>

hasOwn() still has issues if a previous property is undefined, that is why I pointed out the other way and use of nullish coalescing optional chaining.

example

```auto
[{"id":"67945dd7ba95413d","type":"inject","z":"d1395164b4eec73e","name":"index 4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":[1,2,3,4,5]}}","payloadType":"json","x":970,"y":2360,"wires":[["7132475e275fd915"]]},{"id":"7132475e275fd915","type":"function","z":"d1395164b4eec73e","name":"has own or has ownproperty","func":"if (!Object.hasOwn(msg.payload.data.dps, 5)){\n msg.payload = {data:{dps:[1,2,3,4,5,6]}};\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":2360,"wires":[["9bff22b548d19bc2"]]},{"id":"9bff22b548d19bc2","type":"debug","z":"d1395164b4eec73e","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1310,"y":2360,"wires":[]},{"id":"6f4fee8e626dc95d","type":"inject","z":"d1395164b4eec73e","name":"index 5","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":[1,2,3,4,5,6]}}","payloadType":"json","x":970,"y":2420,"wires":[["7132475e275fd915"]]},{"id":"c0da96b3db8a23a7","type":"inject","z":"d1395164b4eec73e","name":"no dps","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{}}","payloadType":"json","x":970,"y":2480,"wires":[["7132475e275fd915"]]},{"id":"abe99dd5257e8f27","type":"inject","z":"d1395164b4eec73e","name":"index 4","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":[1,2,3,4,5]}}","payloadType":"json","x":950,"y":2520,"wires":[["c0039a0b6001719d"]]},{"id":"c0039a0b6001719d","type":"function","z":"d1395164b4eec73e","name":"hsa OwnPropert with nullish","func":"if (!msg.payload.data.dps?.hasOwnProperty(5)){\n msg.payload = {data:{dps:[1,2,3,4,5,6]}};\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":2520,"wires":[["b85dcf65125b7a8a"]]},{"id":"b85dcf65125b7a8a","type":"debug","z":"d1395164b4eec73e","name":"debug 2462","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":2520,"wires":[]},{"id":"2c13e340cd6cebf6","type":"inject","z":"d1395164b4eec73e","name":"index 5","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":[1,2,3,4,5,6]}}","payloadType":"json","x":950,"y":2580,"wires":[["c0039a0b6001719d"]]},{"id":"b02d1f27bc877009","type":"inject","z":"d1395164b4eec73e","name":"no dps","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{}}","payloadType":"json","x":950,"y":2640,"wires":[["c0039a0b6001719d"]]}]

```

With nullish chaining no error is thrown.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 January 2024 19:54 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/8 "2024-01-12T19:54:17Z")

</div>

Well I guess you are swapping 1 possible error for a possible set of other errors - as always, multiple ways to do things, each with strengths and weaknesses.

---

<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:** [12 January 2024 20:04 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/9 "2024-01-12T20:04:56Z")

</div>

> [@TotallyInformation](#):
>
> Well I guess you are swapping 1 possible error for a possible set of other errors

No not really, just pointing out another way as you say

> [@TotallyInformation](#):
>
> as always, multiple ways to do things,

Could you show examples of other errors so others can see the possibilities?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 January 2024 20:12 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/10 "2024-01-12T20:12:30Z")

</div>

Some comments here:

> **[Object.prototype.hasOwnProperty() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)**
>
> The hasOwnProperty() method of Object instances returns a boolean indicating whether this
> object has the specified property as its own property (as opposed to inheriting
> it).

Try this article:

> **[What’s the deal with Object.prototype.hasOwnProperty.call()?](https://dev.to/aman_singh/what-s-the-deal-with-object-prototype-hasownproperty-call-4mbj)**
>
> I am sure you might have seen the following line of code either while reading someone’s code or in a...

Or maybe this:

> **[Why do some developers use Object.prototype.hasOwnProperty.call()?](https://nickang.com/2018-02-04-developers-use-object-prototype-hasownproperty-call/)**
>
> Original photo credit: Pete Wright You might have read someone else’s JavaScript code recently and came across something like this: let name = ”;
> if (Object…

---

<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:** [12 January 2024 20:15 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/11 "2024-01-12T20:15:22Z")

</div>

Could you supply an example flow of the errors you speak of? It would make life easier for others and me to understand your point.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 January 2024 20:16 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/12 "2024-01-12T20:16:49Z")

</div>

Sorry, focused on other things right now.

---

<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:** [12 January 2024 20:17 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/13 "2024-01-12T20:17:17Z")

</div>

~~Maybe later then?~~  
Never mind as you are to busy, I will add it to show what @GogoVega means, by using Object.create() and it you set a null prototype.

```auto
[{"id":"51a806170b1fc6f9","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1000,"y":2520,"wires":[["3a92bd350b6e25b7"]]},{"id":"67945dd7ba95413d","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":980,"y":2340,"wires":[["7132475e275fd915"]]},{"id":"7132475e275fd915","type":"function","z":"d1395164b4eec73e","name":"calling hasOwnProperty as instance with a null prototype, causes error","func":"// the prototype for newly created object.\nmsg.payload = Object.create(null); // Setting `null` as prototype for payload \n\n// Adding a 'name' property on the instance\nmsg.payload.name = 'peter';\n\n// Using `hasOwnProperty` method would cause an error\nmsg.payload.hasOwnProperty('name'); //\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1310,"y":2340,"wires":[["9bff22b548d19bc2"]]},{"id":"9bff22b548d19bc2","type":"debug","z":"d1395164b4eec73e","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1650,"y":2340,"wires":[]},{"id":"4e5c51173f514039","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":980,"y":2420,"wires":[["f0177836c67f7bfa"]]},{"id":"f0177836c67f7bfa","type":"function","z":"d1395164b4eec73e","name":"calling hasOwnProperty as instance with no null prototype","func":"// the prototype for newly created object.\nmsg.payload = Object.create({}); // Setting `null` as prototype for payload \n\n// Adding a 'name' property on the instance\nmsg.payload.name = 'peter';\n\n// Using `hasOwnProperty` method would cause an error\nmsg.payload.hasOwnProperty('name'); //\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1270,"y":2420,"wires":[["8a6fc9bacc7d3ea5"]]},{"id":"8a6fc9bacc7d3ea5","type":"debug","z":"d1395164b4eec73e","name":"debug 2463","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1590,"y":2420,"wires":[]},{"id":"3a92bd350b6e25b7","type":"function","z":"d1395164b4eec73e","name":"calling hasOwnProperty as Object.prototype with null prototype","func":"// the prototype for newly created object.\nmsg.payload = Object.create(null); // Setting `null` as prototype for payload \n\n// Adding a 'name' property on the instance\nmsg.payload.name = 'peter';\n\n// Using `hasOwnProperty` method would cause an error\nObject.prototype.hasOwnProperty.call(msg.payload,'name'); //\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1250,"y":2520,"wires":[["22eaf94ff9b51c88"]]},{"id":"22eaf94ff9b51c88","type":"debug","z":"d1395164b4eec73e","name":"debug 2462","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1530,"y":2520,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)\
**Post date:** [12 January 2024 23:41 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/14 "2024-01-12T23:41:19Z")

</div>

thanks for the replies

I tried to use if (Object.prototype.hasOwnProperty.call(msg.payload.data.dps, "1")) {

but I keep getting this error: "TypeError: Cannot read properties of undefined (reading '1')"

this is the payload:

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

I just want to know if the element 1 under data-\> DPS exists or not, don't care about the value

---

<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:** [13 January 2024 00:05 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/15 "2024-01-13T00:05:01Z")

</div>

The error is coming from somewhere else in your code as I see nothing wrong in the if statement with the object you show.

---

<div class="post-metadata">

**Author:** ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)\
**Post date:** [13 January 2024 01:58 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/16 "2024-01-13T01:58:44Z")

</div>

Thanks for the reply. I'm not sure where the error is coming from.

here is the code:

```auto
let secondpayload = {};
let thirdpayload = {};

if (Object.prototype.hasOwnProperty.call(msg.payload.data.dps, "1")) {

    
if (msg.payload.dps["1"] === "1") {
    msg.colour = "#1db954";
    secondpayload = { colour: "#ffffff" };
    thirdpayload = { colour: "#ffffff" };
global.set("masterblindup", 1);
global.set("masterblinddown", 0);
global.set("masterblindstop", 0);
    return [msg, secondpayload, thirdpayload];

}

else if (msg.payload.dps["1"] === "2") {
     secondpayload = { colour: "#1db954" };
    msg.colour = "#ffffff";
    thirdpayload = { colour: "#ffffff" };
global.set("masterblinddown", 1);
global.set("masterblindup", 0);
    global.set("masterblindstop", 0); 
    return [msg, secondpayload, thirdpayload];

}

else if (msg.payload.dps["1"] === "3") {
    thirdpayload = { colour: "#1db954" };
    msg.colour = "#ffffff";
    secondpayload = { colour: "#ffffff" };
global.set("masterblindstop", 1);
global.set("masterblindup", 0);
global.set("masterblinddown", 0);
    return [msg, secondpayload, thirdpayload];

}
}

```

This is the flow, it's just looking for an output of the Tuya node, which typically outputs the screenshot in the last post .

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1aa0063b28c3f08093bc79e84007b94435ceb3d5.png)

---

<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:** [13 January 2024 04:08 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/17 "2024-01-13T04:08:34Z")

</div>

Missing `data` after `payload` in your if & else ifs (3 places)

> [@Sirhc](#):
>
> `if (msg.payload.dps["1"] === "1") {`

> [@Sirhc](#):
>
> `else if (msg.payload.dps["1"] === "2")`

> [@Sirhc](#):
>
> `else if (msg.payload.dps["1"] === "3"`

---

<div class="post-metadata">

**Author:** ![Sirhc](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sirhc](https://discourse.nodered.org/u/Sirhc)\
**Post date:** [13 January 2024 04:39 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/18 "2024-01-13T04:39:55Z")

</div>

Thanks - that mistake is caused by looking at the computer screen too long lol

---

<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:** [13 January 2024 09:41 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/19 "2024-01-13T09:41:47Z")

</div>

Some thoughts and examples.

You do not need to use `hasOwnProperty` and you should rethink how you save your globals. If you save `masterblind` as a object you can then add extra properties without reworking most of your code later, and all values for masterblind blind are in one global var, for ease of viewing etc.  
example flow to follow

```auto
[{"id":"a5ca6e3cb9934d6f","type":"inject","z":"d1395164b4eec73e","name":"dps 1 = 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":{\"1\":\"1\"}}}","payloadType":"json","x":200,"y":2440,"wires":[["7132475e275fd915"]]},{"id":"7132475e275fd915","type":"function","z":"d1395164b4eec73e","name":"has own or has ownproperty","func":"// set default outputs\nlet output = [\n { colour: \"#ffffff\" },\n { colour: \"#ffffff\" },\n { colour: \"#ffffff\" }\n];\n//set masterblind default, add new propprties here\nlet masterblind = {\n \"up\": 0,\n \"down\": 0,\n \"stop\": 0\n};\n// check dps using nullish coalescing optional chaining\nif (msg.payload?.data?.dps?.[\"1\"] === \"1\") {\n output[0].colour = \"#1db954\";\n masterblind.up = 1;\n global.set(\"masterblind\", masterblind);\n} else if (msg.payload?.data?.dps?.[\"1\"] === \"2\") {\n output[1].colour = \"#1db954\";\n masterblind.down = 1;\n global.set(\"masterblind\", masterblind);\n} else if (msg.payload?.data?.dps?.[\"1\"] === \"3\") {\n output[2].colour = \"#1db954\";\n masterblind.stop = 1;\n global.set(\"masterblind\", masterblind);\n} else {\n// no out put if no dps 1 and dps 1 does not equal 1 or 2 or 3\n output = null;\n}\n// set new global masterblind\nreturn output;","outputs":3,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":2480,"wires":[["9bff22b548d19bc2"],["9bff22b548d19bc2"],["9bff22b548d19bc2"]]},{"id":"67945dd7ba95413d","type":"inject","z":"d1395164b4eec73e","name":"dps 1 = 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":{\"1\":\"2\"}}}","payloadType":"json","x":200,"y":2480,"wires":[["7132475e275fd915"]]},{"id":"1e4513287fbdd28c","type":"inject","z":"d1395164b4eec73e","name":"dps 1 = 3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":{\"1\":\"3\"}}}","payloadType":"json","x":200,"y":2520,"wires":[["7132475e275fd915"]]},{"id":"1824d9f6656e93c1","type":"inject","z":"d1395164b4eec73e","name":"no dps 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"dps\":{\"2\":\"\"}}}","payloadType":"json","x":200,"y":2560,"wires":[["7132475e275fd915"]]},{"id":"9bff22b548d19bc2","type":"debug","z":"d1395164b4eec73e","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"colour","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":2500,"wires":[]}]

```

[edit] fixed global.set() in wrong place.

---

<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:** [13 January 2024 09:49 UTC](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508/20 "2024-01-13T09:49:44Z")

</div>

On top of that sound advice, this approach there is nothing in that function that couldn't/shouldn't be written in regular flow nodes (switch/change nodes)

[Next page](https://discourse.nodered.org/t/advice-on-using-hasownproperty/84508.md?page=2)
