# https://jsfiddle.net/vr4Lbc6p/1/

**URL:** <https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996>\
**Category:** General\
**Created:** [March 5, 2020, 9:05am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996 "2020-03-05T09:05:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![neeyal123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/neeyal123/32/135061_2.png) [@neeyal123](https://forum.freecodecamp.org/u/neeyal123)\
**Post date:** [March 5, 2020, 9:05am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/1 "2020-03-05T09:05:07Z")

</div>

[https://jsfiddle.net/vr4Lbc6p/1/](https://jsfiddle.net/vr4Lbc6p/1/)  
why there is an error , while regex applied on the array element.  
why getting undefined ??

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [March 5, 2020, 9:18am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/2 "2020-03-05T09:18:07Z")

</div>

I have moved your post to a more suitable sub-forum.

To answer your question: Remember to declare your variables, and it would be better to _console.log_ within the map function, or assign the _mapping_ to a variable and `console.log` that.

```auto
let arrayRegex = /.yal/;
array.map(e => {
	console.log(e.match(arrayRegex));
});

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![neeyal123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/neeyal123/32/135061_2.png) [@neeyal123](https://forum.freecodecamp.org/u/neeyal123)\
**Post date:** [March 5, 2020, 9:28am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/3 "2020-03-05T09:28:49Z")

</div>

if i write this code then it will also give the same output  
I thought this solution from net but can not be able to understand,  
Why we have to re return the match.

```auto
let array = ["Neeyal","priyal","Miyal","jiyal","parag","payal"];
arrayRegex = /.yal/;
console.log(array.map(e =>{
return e.match(arrayRegex);
}));

```

In line4 why we rereturn .  
whether match method itself returning value.

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [March 5, 2020, 9:43am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/4 "2020-03-05T09:43:43Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

**Note:** Backticks are not single quotes.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [March 5, 2020, 9:46am UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/5 "2020-03-05T09:46:36Z")

</div>

In this case, it does not have to do with the `match` method, but the way arrow functions work. What you have with the `return` is the same as this:

```auto
console.log(array.map(e => e.match(arrayRegex)));

```

If you include the `{ }` in an arrow function, you have to explicitly define what needs to be returned. Otherwise, the `map` receives no objects to put into an array. Hence, `undefined`.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 7:34pm UTC](https://forum.freecodecamp.org/t/https-jsfiddle-net-vr4lbc6p-1/355996/6 "2021-06-01T19:34:41Z")

</div>

Closed on June 1, 2021, 7:34pm UTC


