# How to output exactly the same object input?

**URL:** <https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780>\
**Category:** General\
**Created:** [4 June 2020 16:59 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780 "2020-06-04T16:59:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [4 June 2020 16:59 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/1 "2020-06-04T16:59:00Z")

</div>

Hi, my goal is to take only the last message in a certain period of time, th first message triggers the counter, if there is no other messages during that time the last one will output as it come in input, the others will be discarded.  
For doing this I'm using a function, it outputs on th first output a reset to the next delay object, the second output will pass the input object. If there will not be any other messages the delay will not be reset and the last message will output.  
My problem is that if I use this code I'll have the input object incapsulated into the msg object, how to avoid it? Thanks

msg2={msg};  
msg={reset:true};  
return [msg,msg2];

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [4 June 2020 17:03 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/2 "2020-06-04T17:03:51Z")

</div>

![a](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66e27dff09c487d42394cc271fa05463613ec620.jpeg)  
the object is inside msg

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [4 June 2020 19:38 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/3 "2020-06-04T19:38:29Z")

</div>

`return [{reset:true},msg];` should do the trick.

Or:

```auto
var msgReset={reset:true};
return [msgReset,msg];

```

The curly brackets around msg gives you the a object including msg. But be aware objects variables only pointing to the object not holding the object itself. Keep this in mind when doing something like `var msg2=msg` Both are now pointing to the same data so if you change msg.payload then msg2.payload results the same changed value. Placing curly brackets does not clone an object. If you need that you can use `var clonedMsg= RED.util.cloneMessage(msg)`

#### `RED`

- `RED.util.cloneMessage(..)` : safely clones a message object so it can be reused

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [4 June 2020 19:54 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/4 "2020-06-04T19:54:43Z")

</div>

thank you a lot!! 🙂 really really helpful!

PS: there is any node who can do itself what I need? Throttle node has different functions but not mine, it eventually outputs the first message discarding the following ones. Thanks

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [4 June 2020 20:08 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/5 "2020-06-04T20:08:53Z")

</div>

I only imagine what your setup is. I thing you have a slider controlling the brightness of a rgb light and if you slide it send to many messages to your light? Perhaps like this:

[https://cookbook.nodered.org/basic/rate-limit-message-stream](https://cookbook.nodered.org/basic/rate-limit-message-stream)

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [4 June 2020 20:14 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/6 "2020-06-04T20:14:38Z")

</div>

well, a kind of ))  
my goal is to limit the number of packes, some come duplicated or too fast changes, and also Alexa has the habit to sent 2 packets when the brightness command is requested, if the light was switched off it switch on and then send intensity, for my purposes I would receive only the intensity command, and manage myself with the proper delays the switch on then change brighness.

For this reason I need something that let out only the last message received, which is supposed the most important, and the final decision only

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [4 June 2020 21:11 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/7 "2020-06-04T21:11:57Z")

</div>

The trigger node can be set to initially send nothing, then the last message received after a period of time...

---

<div class="post-metadata">

**Author:** ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)\
**Post date:** [4 June 2020 22:05 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/8 "2020-06-04T22:05:41Z")

</div>

great, I'll test it!

---

<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:** [18 June 2020 22:15 UTC](https://discourse.nodered.org/t/how-to-output-exactly-the-same-object-input/27780/9 "2020-06-18T22:15:39Z")

</div>

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