Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 16, 2021 Nov 16, 2021

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?

TOPICS
JavaScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Nov 17, 2021 Nov 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);

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2021 Nov 17, 2021
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 17, 2021 Nov 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);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines