# How to remove whitespace in a returned item

**URL:** <https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885>\
**Category:** Help Hub\
**Created:** [January 6, 2021, 9:59am UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885 "2021-01-06T09:59:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![postnewbie2020](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@postnewbie2020](https://community.postman.com/u/postnewbie2020)\
**Post date:** [January 6, 2021, 9:59am UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/1 "2021-01-06T09:59:57Z")

</div>

Hi All 🙂

Wonder if someone could help me with what is probably a easy question. I am using Cherrio to get an array of items from a website. The data returned looks like the following in Console:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/4/f46f9cb011dfedeeefa0707b6bb421d4cd0e87a5.png)

I was wondering if there is a way to remove all the white space?

```
pm.test("Example", function(){

    const $ = cheerio.load(pm.response.text())

    let getAllInstancesOfData = $("td[class='dataDark']").toArray();

    
    let mydata= getAllInstancesOfData[1].children[0].data;

console.log(mydata);
});

```

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 6, 2021, 12:29pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/2 "2021-01-06T12:29:35Z")

</div>

Simplest way would just to replace spaces with nothing.

```auto
myData = myData.replace(' ', '');

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 6, 2021, 12:30pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/3 "2021-01-06T12:30:26Z")

</div>

Hey @postnewbie2020

Maybe something like?

```auto
myData.replace(/\s+/g, '');

```

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 6, 2021, 12:31pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/4 "2021-01-06T12:31:46Z")

</div>

Yeah, this is better than mine.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 6, 2021, 12:33pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/5 "2021-01-06T12:33:32Z")

</div>

Different…not better 😃

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 6, 2021, 1:13pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/6 "2021-01-06T13:13:30Z")

</div>

`mydata.trim()`

Why not this ? 😨 am i missing something

---

<div class="post-metadata">

**Author:** ![postnewbie2020](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@postnewbie2020](https://community.postman.com/u/postnewbie2020)\
**Post date:** [January 6, 2021, 1:23pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/7 "2021-01-06T13:23:16Z")

</div>

@praveendvd - i tried that before submitting my question, and it did not remove the whitespace. Thanks though 🙂

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 6, 2021, 1:28pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/8 "2021-01-06T13:28:09Z")

</div>

Thats interesting is this an open api that we can try out ? did other solution works ?

---

<div class="post-metadata">

**Author:** ![postnewbie2020](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@postnewbie2020](https://community.postman.com/u/postnewbie2020)\
**Post date:** [January 6, 2021, 1:28pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/9 "2021-01-06T13:28:57Z")

</div>

Hi @danny-dainton, thanks for the suggestion. I have implemented this. However, I still get the same thing logged out in the console.

Could it be that what the console is showing, is in fact not white space? This is what I have off the assertion I am doing:

> AssertionError: expected ‘\n\t\t\t\t\t\t9.34\n\t\t\t\t\t’ to deeply equal ‘9.34’

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 6, 2021, 1:35pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/10 "2021-01-06T13:35:32Z")

</div>

@praveendvd I guess it all depends what the structure of the string is - `trim()` only removes whitespace from the beginning and the end of a string.

For example:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/c/aca543ec86b7b37508b0d4906ca6d5810bc017b1.png)

@postnewbie2020 It looks like you have a mixture of whitespace and different carriage returns or newlines. From the image, you have provided it’s difficult to know what’s going on.

Can you provide an example of the HTML page it’s looking at so it will be easier to run locally rather than taking a guess 😃

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 6, 2021, 1:37pm UTC](https://community.postman.com/t/how-to-remove-whitespace-in-a-returned-item/18885/11 "2021-01-06T13:37:10Z")

</div>

> [@postnewbie2020](#):
>
> \n\t\t\t\t\t\t9.34\n\t\t\t\t\t

```
const regex = /\t|\n/ig;
console.log(myData.replaceAll(regex, ''));

```

trim removes only \n and \r , not \t , \t is tab
