# Help with a function - time format "hh:mm" at the start of every array

**URL:** <https://discourse.nodered.org/t/help-with-a-function-time-format-hh-mm-at-the-start-of-every-array/86288>\
**Category:** General\
**Created:** [8 March 2024 20:48 UTC](https://discourse.nodered.org/t/help-with-a-function-time-format-hh-mm-at-the-start-of-every-array/86288 "2024-03-08T20:48:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcoA](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MarcoA](https://discourse.nodered.org/u/MarcoA)\
**Post date:** [8 March 2024 20:48 UTC](https://discourse.nodered.org/t/help-with-a-function-time-format-hh-mm-at-the-start-of-every-array/86288/1 "2024-03-08T20:48:42Z")

</div>

Hey there,

Hope someone can give me a hand.

That function I have:

```auto
let formattedOutput = [];
let tempArray = [];
let chunkSize = 4; // Each game has 4 elements (time, hometeam, awayteam, channel)

for (let i = 0; i < msg.payload.length; i++) {
    tempArray.push(msg.payload[i]);
    if ((i + 1) % chunkSize === 0) {
        formattedOutput.push(tempArray);
        tempArray = [];
    }
}

let finalOutput = formattedOutput.map(game => {
    return game[0] + " " + game[1] + " VS " + game[2] + " " + game[3];
});

msg.payload = finalOutput.join('\n');
return msg;

```

Outputs a string:

```auto
msg.payload : string[6619]
" 18:45 Portimonense FC Porto SPORT TV1 19:00 Go Ahead Eagles PSV SPORT TV2 19:30 Estugarda Union Berlin ELEVEN SPORTS 2 19:30 SD Huesca FC Andorra ELEVEN SPORTS 5 19:45 Napoli Torino SPORT TV4 20:00 Barcelona Mallorca ELEVEN SPORTS 1 20:00 Nice Montpellier ELEVEN SPORTS 4 20:45 CF Estrela Amadora Casa Pia SPORT TV2 20:45 U. Leiria SAD Oliveirense SPORT TV3 22:00 Caxias São José-RS PFC 11:00 FC Porto S19 Benfica S19 PORTO CANAL 11:00 Mafra Penafiel SPORT TV1 11:00 Sp. Braga FM Lank Vilaverdense FM CANAL 11 11:00 Sporting S17 V. Guimarães S17 SPORTING TV 12:00 Holstein Kiel Karlsruher ELEVEN SPORTS 4 12:00 Schalke 04 SC Paderborn 07 ELEVEN SPORTS 3 12:30 Man Utd Everton ELEVEN SPORTS 1 13:00 Valência Getafe ELEVEN SPORTS 2 14:00 Nacional Ac. Viseu SPORT TV+ 14:30 Bayern München Mainz ELEVEN SPORTS 3 14:30 RB Leipzig SV Darmstadt 98 ELEVEN SPORTS 4 15:00 Torreense FM Sporting FM SPORT TV6 15:00 V. ..."

```

What I want it to do, is to output as arrays; every time there's a format "hh:mm", it creates a new array.

Something like:  
array[1]  
18:45 Portimonense Vs FC Porto SPORT TV1  
array[2]  
19:00 Go Ahead Eagles Vs PSV SPORT TV2  
array[3]  
19:30 Estugarda Vs Union Berlin ELEVEN SPORTS 2  
array[4]  
19:30 SD Huesca Vs FC Andorra ELEVEN SPORTS 5  
array[5]  
19:45 Napoli Vs Torino SPORT TV4  
...

Any ideas?

---

<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:** [8 March 2024 22:05 UTC](https://discourse.nodered.org/t/help-with-a-function-time-format-hh-mm-at-the-start-of-every-array/86288/2 "2024-03-08T22:05:43Z")

</div>

Regex match() [String.prototype.match() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)  
e.g.

```auto
[{"id":"9ae215f3a12ef293","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"18:45 Portimonense FC Porto SPORT TV1 19:00 Go Ahead Eagles PSV SPORT TV2 19:30 Estugarda Union Berlin ELEVEN SPORTS 2 19:30 SD Huesca FC Andorra ELEVEN SPORTS 5 19:45 Napoli Torino SPORT TV4 20:00 Barcelona Mallorca ELEVEN SPORTS 1 20:00 Nice Montpellier ELEVEN SPORTS 4 20:45 CF Estrela Amadora Casa Pia SPORT TV2 20:45 U. Leiria SAD Oliveirense SPORT TV3 22:00 Caxias São José-RS PFC 11:00 FC Porto S19 Benfica S19 PORTO CANAL 11:00 Mafra Penafiel SPORT TV1 11:00 Sp. Braga FM Lank Vilaverdense FM CANAL 11 11:00 Sporting S17 V. Guimarães S17 SPORTING TV 12:00 Holstein Kiel Karlsruher ELEVEN SPORTS 4 12:00 Schalke 04 SC Paderborn 07 ELEVEN SPORTS 3 12:30 Man Utd Everton ELEVEN SPORTS 1 13:00 Valência Getafe ELEVEN SPORTS 2 14:00 Nacional Ac. Viseu SPORT TV+ 14:30 Bayern München Mainz ELEVEN SPORTS 3 14:30 RB Leipzig SV Darmstadt 98 ELEVEN SPORTS 4 15:00 Torreense FM Sporting FM SPORT TV6","payloadType":"str","x":510,"y":7600,"wires":[["cfa95e7a06cbd6ae"]]},{"id":"cfa95e7a06cbd6ae","type":"function","z":"d1395164b4eec73e","name":"function 156","func":"msg.payload = msg.payload.match(/\\d\\d:\\d\\d[^\\d\\d:\\d\\d]*/g)\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":7600,"wires":[["902a652132b37f08"]]},{"id":"902a652132b37f08","type":"debug","z":"d1395164b4eec73e","name":"debug 2484","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":7600,"wires":[]}]

```

---

<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:** [22 March 2024 22:06 UTC](https://discourse.nodered.org/t/help-with-a-function-time-format-hh-mm-at-the-start-of-every-array/86288/3 "2024-03-22T22:06:23Z")

</div>

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