# How to loop an array?

**URL:** https://discourse.nodered.org/t/how-to-loop-an-array/20191
**Category:** General
**Created:** [11 January 2020 09:37 UTC](https://discourse.nodered.org/t/how-to-loop-an-array/20191 "2020-01-11T09:37:39Z")
**Posts on this page:** 1
**Showing post:** 16

<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: [14 January 2020 07:41 UTC](https://discourse.nodered.org/t/how-to-loop-an-array/20191/16 "2020-01-14T07:41:58Z")

</div>

Thank you for sharing another approach. Perhaps it is important to point out that there is a different usecase for forEach and map

As I read the docs the map method is useful if you need each result of each iteration as map returns a new array containing the results  
of each iteration

> The `map()` method creates a new array with the results of calling a function for every array element.
> 
> The `map()` method calls the provided function once for each element in an array, in order.

In your first example I would use forEach() instead of map() because the result will be unused.

BTW: console.log by itself does nice colorful formatting of arrays and objects by itself.

> [@Debugging ... little tweaks that perhaps can be useful](https://discourse.nodered.org/t/debugging-little-tweaks-that-perhaps-can-be-useful/19542/9):
>
> Sorry ... not working (here) node.warn('Foo speaking: ${config}'); [image] And this as expected: node.warn('Foo speaking: '+config); [image] and what I normaly do, nice object view but two messages: node.warn('Foo speaking:'); node.warn(config); [image] this works but that's not the way to do it, right? console.log('Foo speaking:',config); [image]

There is a rundown of many possible debug log options including console.log()

---

_[View the full topic](https://discourse.nodered.org/t/how-to-loop-an-array/20191)._
