# Map() method

**URL:** <https://discourse.mozilla.org/t/map-method/94079>\
**Category:** MDN\
**Created:** [March 3, 2022, 1:56pm UTC](https://discourse.mozilla.org/t/map-method/94079 "2022-03-03T13:56:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SebM](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/sebm/32/36549_2.png) [@SebM](https://discourse.mozilla.org/u/SebM)\
**Post date:** [March 3, 2022, 1:56pm UTC](https://discourse.mozilla.org/t/map-method/94079/1 "2022-03-03T13:56:27Z")

</div>

Hello, I am trying to loop over some inputs, and style them depending if condition is true/false.  
[Here is a link to my codepen.](https://codepen.io/m-sebastien/pen/rNYoKBW?editors=1010)

Not too sure why the “Uncaught TypeError: inputs.map is not a function” occurs.  
My understanding is that by using `inputs = document.querySelectorAll("form input)"`, I will select all the inputs from my form and return an array.  
With this one, I would like to iterate on each inputs with `inputs.map((input, i) => {`, and therefor style each of them.

When checking, it appears my `inputs` return a `NodeList`. Could the problem come from here?  
I’ve tried to turn this `NodeList` into an `Array` object, but it didn’t work.

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [March 3, 2022, 4:52pm UTC](https://discourse.mozilla.org/t/map-method/94079/2 "2022-03-03T16:52:58Z")

</div>

Hi @SebM

Instead of using the `map()` function I think it should be possible to loop over the NodeList with a traditional `for` loop since it’s an array-like. I haven’t it tested, though.

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![SebM](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/sebm/32/36549_2.png) [@SebM](https://discourse.mozilla.org/u/SebM)\
**Post date:** [March 4, 2022, 2:21pm UTC](https://discourse.mozilla.org/t/map-method/94079/3 "2022-03-04T14:21:45Z")

</div>

I still don’t understand why the `map()` function was not working, but I’ve used a simple `for` loop and it worked.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [March 4, 2022, 3:33pm UTC](https://discourse.mozilla.org/t/map-method/94079/4 "2022-03-04T15:33:56Z")

</div>

The term “array-like” hints to the fact that a NodeList shares some similarities to an array while still being something different. In some situations it can be used like an array (like in `for` loops), other functionalities are just not support (like `map()`).

I’m sorry I can’t give you a better explanation. 🙁
