# Count array length

**URL:** <https://discourse.nodered.org/t/count-array-length/26865>\
**Category:** General\
**Created:** [18 May 2020 18:11 UTC](https://discourse.nodered.org/t/count-array-length/26865 "2020-05-18T18:11:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pi642s](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@pi642s](https://discourse.nodered.org/u/pi642s)\
**Post date:** [18 May 2020 18:11 UTC](https://discourse.nodered.org/t/count-array-length/26865/1 "2020-05-18T18:11:07Z")

</div>

hi guys  
i'm using homeassistant and node red.

i used a get-entities node to get an array of windows/doors left open.

i'm trying to create a function node that counts the array length and join the friendly name attributes into a string. if anyone could help, thanks so much.

var count = msg.payload.length  
var array = join(payload.attributes.friendly\_name, ", ")  
return [count, array];

---

<div class="post-metadata">

**Author:** ![pi642s](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@pi642s](https://discourse.nodered.org/u/pi642s)\
**Post date:** [18 May 2020 18:28 UTC](https://discourse.nodered.org/t/count-array-length/26865/2 "2020-05-18T18:28:28Z")

</div>

hmm i figured the first one out:

var newMsg = { payload: msg.payload.length };  
return [newMsg, msg];

will give me the length of the array.

but not sure how to join the array together to make a string.

---

<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:** [18 May 2020 19:34 UTC](https://discourse.nodered.org/t/count-array-length/26865/3 "2020-05-18T19:34:52Z")

</div>

maybe the javascript join function ?

---

<div class="post-metadata">

**Author:** ![pi642s](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@pi642s](https://discourse.nodered.org/u/pi642s)\
**Post date:** [19 May 2020 06:59 UTC](https://discourse.nodered.org/t/count-array-length/26865/4 "2020-05-19T06:59:43Z")

</div>

thanks for the suggestion!

---

<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 July 2020 07:07 UTC](https://discourse.nodered.org/t/count-array-length/26865/5 "2020-07-18T07:07:02Z")

</div>

Closed on 18 July 2020 07:07 UTC

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