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

Array element = 'null' displays differently in ESTK Javascript console

Engaged ,
Jan 05, 2019 Jan 05, 2019

Why do these two methods of presenting the contents of an array, where one or more elements is set to 'null', give a different display?

var x

x = [ 1, null, null ];

$.writeln( x );

$.writeln( x[0] + "," + x[1] + "," + x[2] );

The results displayed are:

     1,,

and:

     1,null,null

respectively.

It's consistent regardless of whether x is declared as above, or as: 'new Array', or as: 'new Array( 3 )'.

Just wondering.  It had me chasing my tail for a while during debugging.

TOPICS
Actions and scripting
552
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
Adobe
LEGEND ,
Jan 06, 2019 Jan 06, 2019

Not an answer, but when in the additional line you type: x[1], so directly cell of an array, you'll have null displayed. Probably the same happens when you put specified cell to writeln. For a reason in array they still exist as they are, so as true values in the contrary to calling a single input. Then they are shown as result so in the understable converted form. You do not need that but you can try to make string from array by x.toSource()

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
Engaged ,
Jan 08, 2019 Jan 08, 2019

Indeed, as you say and as I showed, x[1] an be shown to contain 'null'.

My issue in debugging was that the array could contain blank - i.e., "" -  elements, so a display of ',,' wasn't helping me.

I'll mark this as 'Assumed Closed', as I guess its a 'feature'.

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
LEGEND ,
Jan 09, 2019 Jan 09, 2019
LATEST

Good point about problem with distingishing null from '' in this case. The only what can be done is: $.writeln(x.toSource())

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