1 Reply Latest reply on Feb 3, 2015 11:54 AM by George_Johnson

    global.searchVals = [{}]

    lindaeliseruble

      Hello,

       

      I need to understand what the following code means and what it does:

       

      var myArr = [7.4, 0.1, 0.1, 0.4, 9.7, 0.1, 53.1, 0.5, 0.1, 15.5, 4.8, 1.6, 5.7, 1.0];

      var nNumWords = myArr.length;

       

       

       

      global.searchVals = [{}]

      for (i = 0; i<= nNumWords; i++) {

                 global.searchVals[i] = {something1: trim(""+ myArr[i].valueAsString), something2: 0, something3: []};

                 // console.println(myArr[i] + "\n");

                 // console.println(global.srchVals[i] + "\n");

       

      }

       

       

       

       

      First of all, what does the [{}] mean in the first line?

       

       

      I know that you can create an array using var arr=[]; or var arr=new Array();

       

      I know that you can create an object using var obj={}; or var obj=new Object();

       

       

      I understand that the first way uses the array/object literal and the second the array/object constructor.

      javascript - Does better to write: var arr=[]; than var arr=new Array();? - Stack Overflow

       

       

      So what does it mean when you combine the square brackets with the curly brackets?

       

       

       

       

      Also, what does the "someting1:" , "something2:', "something3:" mean?

       

       

      Are they parameter labels for the array global.searchVals[I] ?

       

       

      Why is "global" used?

       

       

      Also,

      When I print the values of "myArr[I]" and "global.searchVals[I]"

       

       

      var myArr = [7.4, 0.1, 0.1, 0.4, 9.7, 0.1, 53.1, 0.5, 0.1, 15.5, 4.8, 1.6, 5.7, 1.0];

      var nNumWords = myArr.length;

       

       

      global.searchVals = [{}]

      for (i = 0; i<= nNumWords; i++) {

                 global.searchVals[i] = {something1: trim(""+ myArr[i].valueAsString), something2: 0, something3: []};

                 console.println(myArr[i] + "\n");

                 console.println(global.searchVals[i] + "\n");

       

      }

       

       

      I get the following results:

       

      What does [object Object] mean?

       

       

      7.4

      [object Object]

      0.1

      [object Object]

      0.1

      [object Object]

      0.4

      [object Object]

      9.7

      [object Object]

      0.1

      [object Object]

      53.1

      [object Object]

      0.5

      [object Object]

      0.1

      [object Object]

      15.5

      [object Object]

      4.8

      [object Object]

      1.6

      [object Object]

      5.7

      [object Object]

      1.0

      [object Object]

      undefined

      [object Object]

       

       

       

       

       

       

      Thanks

       

       

       

      Linda

       

        • 1. Re: global.searchVals = [{}]
          George_Johnson MVP & Adobe Community Professional

          To answer your first series of questions, what that line of code creates and array and assigns an empty object to the first element. You can remove the empty object and the code should work the same. Since an object can't normally be represented by a string, when the code attempts to output the object to the console, it outputs [object Object] instead, which is simply saying that its a generic object.