# \`SWITCH\` node question about options

**URL:** <https://discourse.nodered.org/t/switch-node-question-about-options/76086>\
**Category:** General\
**Created:** [3 March 2023 22:56 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086 "2023-03-03T22:56:48Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [4 March 2023 16:10 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/21 "2023-03-04T16:10:52Z")

</div>

> [@Sean-McG](#):
>
> test the length of Strings

It would help if it was more verbose, but I guess its implied by **"test the length of Strings"**

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2023 16:19 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/22 "2023-03-04T16:19:35Z")

</div>

It isn't the string "0" that is the issue, it is number 0 or any number for that matter. Neither 'is empty' nor 'is not empty' pass. That is implied by:  
"The `is empty` and `is not empty` rules can be used to test the length of Strings, Arrays and Buffers, or the number of properties an Object has"  
as Numbers do not appear in that list. However, the next sentence  
"Neither rule will pass if the property being tested has a boolean, null or undefined value."  
Should read  
"Neither rule will pass if the property being tested has a numeric, boolean, null or undefined value."

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [4 March 2023 17:09 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/23 "2023-03-04T17:09:15Z")

</div>

What the node needs is a way to check `has key` on `msg`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2023 21:15 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/24 "2023-03-04T21:15:16Z")

</div>

You can test `msg.key` is null for that.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [4 March 2023 22:45 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/25 "2023-03-04T22:45:27Z")

</div>

Hi Colin, what I meant was property `msg` then select `has key` `important_piece`. At the moment having just `msg` as a property is invalid

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 March 2023 05:03 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/26 "2023-03-05T05:03:37Z")

</div>

Yeah: silly me.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 March 2023 07:28 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/27 "2023-03-05T07:28:28Z")

</div>

> [@Buckskin](#):
>
> having just `msg` as a property is invalid

Yes, I know. I agree that occasionally that would be useful. I was pointing out that there is a workaround, which is to test the property for null.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [5 March 2023 13:48 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/28 "2023-03-05T13:48:53Z")

</div>

Sorry Colin, I got so caught up in the `is empty` `is not empty` discussion I forgot that it was agreed right at the biggening that testing for `null` was the solution 😊

---

<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:** [4 May 2023 13:48 UTC](https://discourse.nodered.org/t/switch-node-question-about-options/76086/29 "2023-05-04T13:48:54Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/switch-node-question-about-options/76086.md?page=1)
