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

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:

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

Hi @lstiburkova

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

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

Output;
image

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:

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

Thank you again for your time!