# How to get length of a variable value (not of a json)

**URL:** <https://community.postman.com/t/how-to-get-length-of-a-variable-value-not-of-a-json/36729>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [June 30, 2022, 3:14pm UTC](https://community.postman.com/t/how-to-get-length-of-a-variable-value-not-of-a-json/36729 "2022-06-30T15:14:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lstiburkova](https://avatars.discourse-cdn.com/v4/letter/l/c0e974/32.png) [@lstiburkova](https://community.postman.com/u/lstiburkova)\
**Post date:** [June 30, 2022, 3:14pm UTC](https://community.postman.com/t/how-to-get-length-of-a-variable-value-not-of-a-json/36729/1 "2022-06-30T15:14:32Z")

</div>

Hello,

How do I get a length of a value stored in a variable?

I have a variable `{{var01}}` which is filled by a script after a request run.  
Then I need to get it’s length and work with it.

Something like this:

```auto
var someValue = pm.collectionVariables.get("Var01");
var valueLength = someValue.length;

```

I’ve found a way for json objects, but not for plain strings.

Thank you in advance,  
Zuzana

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 30, 2022, 10:30pm UTC](https://community.postman.com/t/how-to-get-length-of-a-variable-value-not-of-a-json/36729/2 "2022-06-30T22:30:18Z")

</div>

Hi @lstiburkova

Pretty much exactly how you wrote the example, using .length …

```auto
const str = 'Life, the universe and everything.';
console.log(str.length);

```

Output;  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/6/658916cfe8f7f1a22678df00715196f0d4ba277d.png)

---

<div class="post-metadata">

**Author:** ![lstiburkova](https://avatars.discourse-cdn.com/v4/letter/l/c0e974/32.png) [@lstiburkova](https://community.postman.com/u/lstiburkova)\
**Post date:** [July 1, 2022, 10:20am UTC](https://community.postman.com/t/how-to-get-length-of-a-variable-value-not-of-a-json/36729/3 "2022-07-01T10:20:35Z")

</div>

Thank you for the replay.  
I found out what was the problem - in the type of the variable.  
If I set the` var` or `const` from the collection variables, it is not a `string` but `any` - so that the `length` property cannot be used.  
I need to re-type it to string first.

This is working:

```auto
var someValue = pm.collectionVariables.get("Var01").toString();
console.log(someValue.length);

```

Thank you again for your time!
