# Remove empty string inside array

**URL:** <https://community.n8n.io/t/remove-empty-string-inside-array/20009>\
**Category:** Questions\
**Tags:** javascript, code\
**Created:** [November 21, 2022, 4:01pm UTC](https://community.n8n.io/t/remove-empty-string-inside-array/20009 "2022-11-21T16:01:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriele\_Bracciali](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/gabriele_bracciali/32/31293_2.png) [@Gabriele\_Bracciali](https://community.n8n.io/u/Gabriele_Bracciali)\
**Post date:** [November 21, 2022, 4:01pm UTC](https://community.n8n.io/t/remove-empty-string-inside-array/20009/1 "2022-11-21T16:01:21Z")

</div>

Hello!  
I would like to filter this list that i have in input and remove all the empty string

 ![Screenshot 2022-11-21 at 16.58.49](https://europe1.discourse-cdn.com/n8n/original/3X/7/5/75d73c2db014d5f04f27f62727f32019135ea6db.png)  
So far, i’ve tried through the code Node with the function .filter but it return me the same value.  
 ![Screenshot 2022-11-21 at 17.00.05](https://europe1.discourse-cdn.com/n8n/original/3X/f/0/f05eb40d576e054b457d21184c90e32389435b0d.png)

Let me know your opinion!

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![eldala07](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/eldala07/32/19349_2.png) [@eldala07](https://community.n8n.io/u/eldala07)\
**Post date:** [November 22, 2022, 12:40am UTC](https://community.n8n.io/t/remove-empty-string-inside-array/20009/2 "2022-11-22T00:40:18Z")

</div>

Hello 😊

I tried to reproduce your usecase as close as possible.

Here is the code block I propose:

```auto
const mainJson = $('Set').all()[0].json;
const resultJson = {};

const keys = Object.keys(mainJson);
keys.forEach(key => resultJson[key] = mainJson[key].filter(value => !!value));

return [{"json": resultJson}];

```

And here is the result:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/a/e/ae00ef9409a78cc9d75af67a6311feb35ca557f9.png)

You can also play with the workflow here:

Don’t hesitate to check input data with `console.log` !  
It helps a lot for debugging this kind of situation 😉

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/36532_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [November 29, 2022, 12:40am UTC](https://community.n8n.io/t/remove-empty-string-inside-array/20009/3 "2022-11-29T00:40:48Z")

</div>

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