Skip to main content
Participant
November 16, 2021
Answered

How to return the length of a variable in Javascript in Acrobat DC

  • November 16, 2021
  • 2 replies
  • 2168 views

I am trying to return the length of a variable in Javascript in Adobe Acrobat DC. I tried Googling and all I could find were posts saying to use Length, Len, length, le but none of them worked. I would get a reference error saying that the function was not defined. Any ideas?

This topic has been closed for replies.
Correct answer try67

The correct property to use is "length", but it only applies for strings and arrays.

If you have another type of variable you'll have to convert it to one of those two types first, and then you'll be able to find out its length.

For example, if you have a Number variable and want to find out how long it is, you can do so like this:

 

var a = 123;
app.alert("Length of 'a' is: " + a.toString().length);

 

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 17, 2021

The correct property to use is "length", but it only applies for strings and arrays.

If you have another type of variable you'll have to convert it to one of those two types first, and then you'll be able to find out its length.

For example, if you have a Number variable and want to find out how long it is, you can do so like this:

 

var a = 123;
app.alert("Length of 'a' is: " + a.toString().length);

 

Bernd Alheit
Community Expert
Community Expert
November 17, 2021

Can you explain the issue? Is this a variable with a text string?

Participant
November 17, 2021

I got it to work but thank you for the williness to help.