# Add timestamp item inside array

**URL:** <https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158>\
**Category:** General\
**Created:** [24 May 2021 13:01 UTC](https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158 "2021-05-24T13:01:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nabil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nabil/32/42322_2.png) [@Nabil](https://discourse.nodered.org/u/Nabil)\
**Post date:** [24 May 2021 13:01 UTC](https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158/1 "2021-05-24T13:01:58Z")

</div>

Hi,  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b5b8cc713fb79b09f85769ffdac7e662f9dcfd0.png)

I'm reading Modbus array [5 items] and I need to add -in the first position- the 6th item (timestamp) to log them in a csv file.  
I don't know how to insert the timestamp,  
any help is appreciated.

here I created an array to simulate the Modbus input

```auto
[{"id":"bdca0aac.97159","type":"file","z":"f971f785.8dc938","name":"file","filename":"log.csv","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":610,"y":60,"wires":[[]]},{"id":"2aa05887.c98908","type":"csv","z":"f971f785.8dc938","name":"","sep":";","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\n","temp":"Date,Temp,Cap,REG3,REG4","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":410,"y":60,"wires":[["bdca0aac.97159"]]},{"id":"1ae9aac4.938ea5","type":"inject","z":"f971f785.8dc938","name":"Array 5","props":[{"p":"payload"},{"p":"topic","v":"[\"Temp\",\"Cap\",\"REG3\",\"REG4\",\"REG5\"]","vt":"jsonata"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[2973,68,6208,56,45556]","payloadType":"jsonata","x":200,"y":60,"wires":[["2aa05887.c98908","c5f26fc7.8e8128","baeed3b9.eac98","3e0554e0.46cc8c"]]}]

```

---

<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:** [24 May 2021 13:16 UTC](https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158/2 "2021-05-24T13:16:56Z")

</div>

```auto
msg.payload.unshift(Date.now())
return msg;

```

```auto
[{"id":"2aa05887.c98908","type":"csv","z":"b872cb4b.5a6448","name":"","sep":";","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\n","temp":"Date,Temp,Cap,REG3,REG4","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":710,"y":760,"wires":[["6e6fe6d9.52fe08"]]},{"id":"1ae9aac4.938ea5","type":"inject","z":"b872cb4b.5a6448","name":"Array 5","props":[{"p":"payload"},{"p":"topic","v":"[\"timestamp\", \"Temp\",\"Cap\",\"REG3\",\"REG4\",\"REG5\"]","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[2973,68,6208,56,45556]","payloadType":"json","x":410,"y":760,"wires":[["79765b97.b1ae44"]]},{"id":"79765b97.b1ae44","type":"function","z":"b872cb4b.5a6448","name":"","func":"msg.payload.unshift(Date.now())\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":760,"wires":[["2aa05887.c98908"]]},{"id":"6e6fe6d9.52fe08","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":760,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Nabil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nabil/32/42322_2.png) [@Nabil](https://discourse.nodered.org/u/Nabil)\
**Post date:** [24 May 2021 13:19 UTC](https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158/3 "2021-05-24T13:19:03Z")

</div>

It solved my problem  
I dont know how to thank you  
Many thanks ❤

---

<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:** [7 June 2021 13:19 UTC](https://discourse.nodered.org/t/add-timestamp-item-inside-array/46158/4 "2021-06-07T13:19:37Z")

</div>

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