HISE Logo Forum
    • Categories
    • Register
    • Login

    Print Object Value for Object Key; not working

    Scheduled Pinned Locked Moved Scripting
    22 Posts 3 Posters 1.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ten7kurT
      ten7kur
      last edited by ten7kur

      Hi all,
      Cant manage to get this working..
      Went trough @d-healey HISE scripting 101, it should work.... but does not

      My Viewport 2 displays: [Array][Array][Array]
      Why?

      Thanks!
      @Line43 is my problem

      HiseSnippet 2736.3oc6Zs0baabEFPxvwhUL0Iien8gNyNZxCTIJhWrkhcTcCkDki7TYaUQYGOiJqJD3RxUBDKFfkRhwilI+j5OA+SJu0GaO6tXAV.dU2731X5wivd6b91yd1yd9VfcCnN3vPZfg4b622GaXNuU89drNa1wl3Y77ZFl4rNJfdVHNXUiM56aGFhaZXZN6Oxa2bt6XH98q+vF1t1dN3jpLLdCk3f2gzkvRpc2p+Uhq6yrah2mzUq2Op5ycndaRco8.rLqUICeamSraieoMuayXYXd2sZRXzf5LaFNzv7NaPa1udG5Ydx9+FRH4HWLuPYi5ffjU+LpaSNh40ZrYGhaycUy4PCCSqcSr.yJs.Ov5Ejlj35SrD2Wz.JYD51CyYFG7JqCuRSO7L0f2cjv6Krp6DP7YIsvw1uy54dLbPKaXIPGVx9ZLy+9dVaRgd3wVtq8I3mE.EhGQgUKUZIzJkJs3Z4ygfe4yUrH5oC9Cc.ptcWeWbWaezlvDsMMffCQMFRmQEKlOGrlFxPmZGjLtcHgrC2b88KidJRAo1X1lzt9TOnPgEFrqKvA1XjUkoWVUDxRLAOkfOymFvPtPaHVGLhvvcCymaP.rbHFDVuPLulEVBwB5g4xYPwOpdlf9Sv8WOHvtOf4CZr1PZnRTKwqD98XnddMwAHGoMuut77fcHg7grvF0NbmdMOizdgk3O+19+L7P8ZGtuc2irkO91yOGdX6sOzoS.IbgFqg3FCjTUBkw5PBQmAaRQc.eSg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7LMtMgXWam.5gNxDf3.8dhZfd5Itz34rdAuLJ9B1s3nznKDZ6PGmTRYfwT4JLlGdEFyitBiYkqvXV8JLlu6JLlGO1wvOUY8dLZWYHBnhc2JJSzsR7pJEmfK3s6iCX7WIioYM7oPhGxcUyAwzCOgQ8EuFoHBBfCvDdQRmG+ZQptW09wE9kZUOizj0IthRWTsClzti1Gk0SqxvmytNuDJaWRautBbdWKWbKFeZNYnm5ESkLALdi1Dv3wYl.99CLAVNZBbIdoVSEhuLunKM3uiF7e+eKC7M9GYg+uXWM5ty.WKSSnFACRwqqpVt50xs81o.2bW92aVB39msFG3d+QSFbLJ0kQ741Mgri.6ez5.wWKPibY96MQ9Slypc1Qxa+6V4it6lHs.yYFBd4ujxaY7Ns4TbK88Jd8XJdk+nR8m5OpzTDCUc68U0oDpp8eUMEYvDcMDdfpFuW0Lj.SlJYX.lzPL8uj43.b+RZRQ7KolDVeI0khxmbW6.j9R58GUL9tODyq3F0NbC9qoJnXoA9.N9ro6C3.D2t1fAPqmaPZGqJYM5dywFcAvz9vhMt03a9AXW3sa71YmN3ZbKQv0bVc5s5aIh41lf8gNgTrZU07fpwTZUU8UU0oydkrEkmdaw0jA7+ycN4r+l+bxqD28OFWmGAw+OnPcJnjaYNC+H1XR4V7SGUzxsL+OvuDd4xyNiXlKabZt8.yYht6fDW5K4EGbsQ4mt.g+e7BDLm03+RC4tMm```
      
      
      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        I get this in the Console

        Interface: BD
        Interface: Ludwig
        Interface: SD
        Interface: Tamba
        Interface: HH
        Interface: chris
        

        What are you expecting to see?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        ten7kurT 1 Reply Last reply Reply Quote 0
        • ten7kurT
          ten7kur @d.healey
          last edited by ten7kur

          @d-healey said in Print Object Value for Object Key; not working:

          u expecting to see

          Yes same here.
          Im expecting to get:
          BD
          item1 = Ludwig
          item2 = Xyz

          SD
          item1 = Tamba
          item2 = SD_xxx

          HH
          item1 = chris

          But its only printing the first variable of each category..

          1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey
            last edited by d.healey

            Use Console.print(trace(obj)); to see the contents of the object.

            For global objects you can also right click in the script watch table to see the contents.

            d7080a1f-0e3f-4c4b-bbe8-2d61e308e128-image.png

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            ten7kurT 1 Reply Last reply Reply Quote 0
            • ten7kurT
              ten7kur @d.healey
              last edited by ten7kur

              @d-healey said in Print Object Value for Object Key; not working:

              Use Console.print(trace(obj)); to see the contents of the object.

              For global objects you can also right click in the script watch table to see the contents.

              d7080a1f-0e3f-4c4b-bbe8-2d61e308e128-image.png

              I did.
              So if at line 2 (in your example)= BD
              how do i specify the index? Ive tried [0], [1] [2] [3] . It doesnt work..

              1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey
                last edited by

                The index of BD?

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                ten7kurT 1 Reply Last reply Reply Quote 0
                • ten7kurT
                  ten7kur @d.healey
                  last edited by

                  @d-healey said in Print Object Value for Object Key; not working:

                  The index of BD?

                  Looking at the Script Watch Table its line 2. But i think im not understanding something. It should be and is @index = 0??

                  d.healeyD 1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey @ten7kur
                    last edited by

                    @ten7kur Obj is an object not an array. So obj doesn't have indexes like [0],[1],[2], etc. BD is an array though so BD[0] = "Ludwig".

                    Libre Wave - Freedom respecting instruments and effects
                    My Patreon - HISE tutorials
                    YouTube Channel - Public HISE tutorials

                    1 Reply Last reply Reply Quote 0
                    • ten7kurT
                      ten7kur
                      last edited by

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • ten7kurT
                        ten7kur
                        last edited by

                        I understand that "Obj" is a object. I thought an object holds arrays....

                        d.healeyD 1 Reply Last reply Reply Quote 0
                        • ten7kurT
                          ten7kur
                          last edited by

                          How can i access the arrays?

                          d.healeyD 1 Reply Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @ten7kur
                            last edited by

                            @ten7kur It does, "BD" is a key and its value is an array.

                            Libre Wave - Freedom respecting instruments and effects
                            My Patreon - HISE tutorials
                            YouTube Channel - Public HISE tutorials

                            1 Reply Last reply Reply Quote 0
                            • d.healeyD
                              d.healey @ten7kur
                              last edited by d.healey

                              @ten7kur said in Print Object Value for Object Key; not working:

                              How can i access the arrays?

                              obj.BD or obj.SD, etc.

                              Libre Wave - Freedom respecting instruments and effects
                              My Patreon - HISE tutorials
                              YouTube Channel - Public HISE tutorials

                              ten7kurT 1 Reply Last reply Reply Quote 0
                              • ten7kurT
                                ten7kur @d.healey
                                last edited by ten7kur

                                @d-healey said in Print Object Value for Object Key; not working:

                                @ten7kur said in Print Object Value for Object Key; not working:

                                How can i access the arrays?

                                obj.BD or obj.SD, etc.

                                keyArray2.push(obj[BD]);? ..ooops typo. I meant :

                                keyArray2.push(obj[k][BD]);
                                

                                I cant get the keyArray2 to populate correct, its displaying the fist value from each category.. as before

                                const var SamplemapList_CAT1 = Content.getComponent("SamplemapList_CAT1");
                                const var SamplemapList_CAT2 = Content.getComponent("SamplemapList_CAT2");
                                
                                // viewport list the items
                                SamplemapList_CAT1.set("useList", true);
                                SamplemapList_CAT2.set("useList", true);
                                const var keyArray = [];
                                const var keyArray2 = [];
                                const var keyArray3 = [];
                                    
                                // put under category
                                const var names = ["BD_Ludwig","BD_Xyz","SD_Tamba","SD_Xxx","HH_chris"]; 
                                
                                     
                                
                                // this will hold the samplenames sorted by category
                                     var obj = {};
                                
                                     for(n in names)
                                         {
                                         // This splits the string into a list using the given separator
                                         var sp = n.split("_");
                                
                                         var drm_category = sp[0];
                                         var drm_sampleName = sp[1];
                                
                                         // We can check if the category is already used
                                         if(isDefined(obj[drm_category]))
                                             obj[drm_category].push(drm_sampleName); // append to the existing list
                                         else
                                             obj[drm_category] = [drm_sampleName]; // create a new list at the key
                                         }
                                		 
                                    for (k in obj)
                                    {
                                        //Lists CAT1
                                        keyArray.push(k);
                                         Console.print(k);
                                        
                                         //List CAT
                                        keyArray2.push(obj[k][BD]);
                                        keyArray3.push(obj[k][SD]);
                                        //keyArray2.push(k[obj]);
                                        Console.print(obj[k][BD]);
                                    }
                                    
                                 
                                    
                                    
                                // Update the viewports
                                SamplemapList_CAT1.set("items", keyArray.join("\n"));
                                SamplemapList_CAT2.set("items", keyArray2.join("\n"));
                                
                                ten7kurT 1 Reply Last reply Reply Quote 0
                                • ten7kurT
                                  ten7kur @ten7kur
                                  last edited by

                                  @ten7kur
                                  Even in something simple like this code below , i cant get "a" to show all its contents; all it prints is "a" and its first value "10" + undefined parameter 0

                                  const var o = {a:[10,11,12], b:14, c:15, d:16}
                                  
                                      for (k in o)
                                      {    
                                          Console.print(o[k][a]);
                                      }
                                  

                                  If i do:

                                  const var o = {a:[10,11,12], b:14, c:15, d:16}
                                  
                                      for (k in o)
                                      {    
                                          Console.print(o[k]);
                                      }
                                  

                                  Then i get a print out of "[Array] 14 15 16"
                                  What am i not understanding?
                                  Thanks

                                  LindonL 1 Reply Last reply Reply Quote 0
                                  • LindonL
                                    Lindon @ten7kur
                                    last edited by Lindon

                                    @ten7kur

                                    so in your simple example:

                                    You have an object called o

                                    it has 4 attributes named a,b,c and d

                                    you need to reference these attributes in the object

                                    Console.print(o.a);
                                    

                                    will print "Array"

                                    Console.print(o.a[0]);
                                    

                                    will print 10

                                    Console.print(o.b);
                                    

                                    will print 14

                                    so if you want to iterate through the attributes of o

                                    const var o = {a:[10,11,12], b:[14,22,77], c:[1,9,6,-415], d:[16,22,11,56]}
                                    
                                    
                                        for (k in o)
                                        {    
                                            // k will first hold a, then b then c then d
                                            var key = o[k];
                                            Console.print(key[0]);
                                        }
                                    

                                    so this will print:
                                    10
                                    14
                                    1
                                    16

                                    so with some better name vars

                                    const var o = {a:[10,11,12], b:[14,22,77], c:[1,9,6,-415], d:[16,22,11,56]}
                                    
                                    for (key in o)
                                    {    
                                        // key will first hold a, then b then c then d
                                        var attrib = o[key];
                                        for (val in attrib)
                                        {
                                            Console.print(val);
                                        };
                                    };
                                    

                                    HISE Development for hire.
                                    www.channelrobot.com

                                    ten7kurT 1 Reply Last reply Reply Quote 0
                                    • ten7kurT
                                      ten7kur @Lindon
                                      last edited by

                                      @Lindon said in Print Object Value for Object Key; not working:

                                      const var o = {a:[10,11,12], b:[14,22,77], c:[1,9,6,-415], d:[16,22,11,56]}
                                      
                                      for (key in o)
                                      {    
                                          // key will first hold a, then b then c then d
                                          var attrib = o[key];
                                          for (val in attrib)
                                          {
                                              Console.print(val);
                                          };
                                      };
                                      

                                      Aha, i see.
                                      Console is printing all the values!Great! But going back to my first example, i cant manage to display it in a viewport.
                                      The array "attrib" only shows 1 value "chris"... Why? yet Console prints all??

                                      HiseSnippet 2724.3oc6Z0sbaabEFPxvNjUL0Iiun2zY1gStfpQQhj1RwNrtkRhxQdprspnrimQkUEDbI4JAhEyhkRhwimIOR8QvOH8gnuAsmcweK.+UThdbaL0EBX+4b91yd1y47AfCYTKrmGkoom43AtXM8ULpOvg2c2tlDGsmWSSOqQSF8ROLaKscF3Z54gaooqu7OJ5WOyczj+92+4cLsMcrvwMoo8FJwBe.oGgG25gU+KDa6mY1BeLomxneT0maQc1kZS6CXYYihZtlVma1A+RSwvVxPS+t60hvor5bSN1SS+N6PaMndW5kN9i+MDORSar3lRZ0AA427yn1sDHVzp1tcI1sNLbM6oooabXrEXYeKvCLdAoEIp8XKw8kcfhmgp8PeoIAuRpvq3rCOcE3cGe38UF0sXDWdbOBr8aLdtCGyZaBaApvxerZK8utqwtTXDN706YdN9YL3lnYTXqhEWCsYwhqVIWVD7KW1M1.8zg+gNAU2rmqMtmoKZWXg1gxHXOTiQLXzFajKKrm5wQWXxhm2ADO9o6t8wkPOEEBoNX9tzdtTG3lB4Gdn4E.aBxp7rKqxRYIWfWPvW5RYbjMzGh2EiHbbOubYGF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jP+WFbDBAm4Y7Eu0ZEC4IZjHV8MPaGQ6KJ7OLDkADEyOgtZrrxZA2UL3oOBTGJJLfeWovdJE7T8gdJEzilUnH.MGbseMCKCzDg3PAYasg3o1o1S8fjGB7HpzXQBwdlVL5oV9E.I.5WHaAFoi7gFmw3Eh6QwObcAJ05Ag1N0xJgTFZNkmi47v4XNOZNlylywb1ZNly2OGy4wSbNhrJa2mS64Gh.Z3v8BpDcuXuphQE3Bd6tXFW75Xz0qgu.J7v+TUFHlt24bpq7UHEPP.b.lxKQ5pnWKR0ipNH5leoV0KIs3ciZn36q1ES5zU4qt4oU43q32jW.koMoiSOINuqgMtMWrLmNzS7RohW.ZuQYAn83TK.W2gV.qGr.tFuPqYBwWmWxkB7OPA9e3ulB9Z+8zv+WLqF7ryDuiLwKISxfT95ppksdsr6ueBvk45+dyhA2+n8j.2GZNcvwoTaNwUX2jxN.r2yP9MibaTsj9xJYJheWeKjugpaih.zWZD3U7JIWv3cVqfXA84mcy3EN2eifty72HXBZfgC6CUUI.F15+rZBpew5ZDr9B67KplhxW7RIEeu3NhH6EuFGhoWbWgz7haIliWbaIH34eFcHJdwi9SJ9c2GhvswN0NcGwKkhsQwg9TMt2r8oZ.h6PSv.nLxcHchTkeKpdyQFcIvT9NQ0VXrK+HbJbwFuc4YCtZKH5r5KqRlU8HQDS1XrOxETHG1vVdP0HBrgM8MUUIuNW1hRyts3Fx28+4xSt7u5ySNWL0+TbedLz7+nB0Yf.tg9RhTrQTv8+FzBHgan+efewrv8ycFvC2uyY4YEnuTvSJH1k9Z9XBtwn7yOtf+e7wEnur1+EfLcwgy
                                      
                                      Content.makeFrontInterface(600, 500);
                                          
                                      // =================== [ Samplemap Categories ] ================== //
                                      const var SamplemapList_CAT1 = Content.getComponent("SamplemapList_CAT1");
                                      const var SamplemapList_CAT2 = Content.getComponent("SamplemapList_CAT2");
                                      
                                      // viewport list the items
                                      SamplemapList_CAT1.set("useList", true);
                                      SamplemapList_CAT2.set("useList", true);
                                      const var keyArray = [];
                                      //const var val1 = [];
                                          
                                      
                                      // put under category
                                      const var names = ["BD_Ludwig","BD_Xyz","SD_Tamba","SD_Xxx","HH_chris"]; 
                                      
                                          
                                      // this will hold the samplenames sorted by category
                                           var obj = {};
                                      
                                           for (n in names)
                                               {
                                               // This splits the string into a list using the given separator
                                               var sp = n.split("_");
                                      
                                               var drm_category = sp[0];
                                               var drm_sampleName = sp[1];
                                      
                                               // We can check if the category is already used
                                               if(isDefined(obj[drm_category]))
                                                   obj[drm_category].push(drm_sampleName); // append to the existing list
                                               else
                                                   obj[drm_category] = [drm_sampleName]; // create a new list at the key
                                               }
                                      		 
                                               
                                          for (k in obj)
                                          {
                                               //Lists CAT1
                                               keyArray.push(k);
                                               //Console.print(k);
                                              
                                               //List CAT2
                                               var attrib = obj[k];
                                               for (val in attrib)
                                               { 
                                                  var val1 = val;
                                                  Console.print(val1);
                                               }
                                      
                                          }
                                          
                                          
                                      // Update the viewports
                                      SamplemapList_CAT1.set("items", keyArray.join("\n"));
                                      SamplemapList_CAT2.set("items", [val1].join("\n"));
                                      
                                      
                                      LindonL 1 Reply Last reply Reply Quote 0
                                      • LindonL
                                        Lindon @ten7kur
                                        last edited by Lindon

                                        @ten7kur said in Print Object Value for Object Key; not working:

                                        Aha, i see.
                                        Console is printing all the values!Great!

                                        No. its not, I think you maybe still not quite there...your code:

                                        const var o = {a:[10,11,12], b:14, c:15, d:16}
                                        
                                            for (k in o)
                                            {    
                                                Console.print(o[k][a]);
                                            }
                                        

                                        So Console is being asked to print something about o...

                                        o[k][a]

                                        -- so break this down:

                                        o - the object
                                        k - an attribute of o
                                        a - huh?

                                        as you move through your loop K contains the attribute - so first time through
                                        o = your object
                                        k = the first attribute of your object (which first time thru is an attribute called "a")
                                        a = well who knows what this equals but it really should be pointing at an index - its important to realise that even though you've named your attribute "a" in your object theres no way for the code to get at "an attribute called a" unless you explicitly call it - maybe like this:

                                        Console.print(o.a)

                                        in the loop you are running the code has no idea that theres something called "a" in your object

                                        So as you say "all it prints is "a" and its first value "10" + undefined parameter 0"

                                        so Console.print essentially does this:

                                        print o[k] -- so it prints "a"
                                        print o[k][a] -- er there is no attribute called "a" on the output of o[k] so its undefined...so prints undefined...

                                        All of your problems are (as far as I can see) based on not understanding arrays and objects in javascript - stop, slow down, go do an online javascript course (they're free) and you will be much better off...

                                        HISE Development for hire.
                                        www.channelrobot.com

                                        ten7kurT 1 Reply Last reply Reply Quote 0
                                        • d.healeyD
                                          d.healey
                                          last edited by d.healey

                                          https://www.tutorialspoint.com/javascript/javascript_objects.htm
                                          https://www.tutorialspoint.com/javascript/javascript_arrays_object.htm

                                          Libre Wave - Freedom respecting instruments and effects
                                          My Patreon - HISE tutorials
                                          YouTube Channel - Public HISE tutorials

                                          1 Reply Last reply Reply Quote 1
                                          • ten7kurT
                                            ten7kur @Lindon
                                            last edited by

                                            @Lindon said in Print Object Value for Object Key; not working:

                                            @ten7kur said in Print Object Value for Object Key; not working:

                                            Aha, i see.
                                            Console is printing all the values!Great!

                                            No. its not, I think you maybe still not quite there...your code:

                                            const var o = {a:[10,11,12], b:14, c:15, d:16}
                                            
                                                for (k in o)
                                                {    
                                                    Console.print(o[k][a]);
                                                }
                                            

                                            So Console is being asked to print something about o...

                                            o[k][a]

                                            -- so break this down:

                                            o - the object
                                            k - an attribute of o
                                            a - huh?

                                            as you move through your loop K contains the attribute - so first time through
                                            o = your object
                                            k = the first attribute of your object (which first time thru is an attribute called "a")
                                            a = well who knows what this equals but it really should be pointing at an index - its important to realise that even though you've named your attribute "a" in your object theres no way for the code to get at "an attribute called a" unless you explicitly call it - maybe like this:

                                            Console.print(o.a)

                                            in the loop you are running the code has no idea that theres something called "a" in your object

                                            So as you say "all it prints is "a" and its first value "10" + undefined parameter 0"

                                            so Console.print essentially does this:

                                            print o[k] -- so it prints "a"
                                            print o[k][a] -- er there is no attribute called "a" on the output of o[k] so its undefined...so prints undefined...

                                            All of your problems are (as far as I can see) based on not understanding arrays and objects in javascript - stop, slow down, go do an online javascript course (they're free) and you will be much better off...

                                            HiseSnippet 2721.3oc6Z0sbaabEFPxvNjUL0Iiun2zY1gStfpQQhj1RwNrtghhxQdprspnrimQgQEDbI4JAhEC1kRhwimIOR8QvOJ8QHuAsmcweK.+URldbaL0EBX+4b91yd1y47AfC7nVXFi5oom4ngtXM8ULZLzg2amdlDGsmVWSOqQKO5ELr2VZ0F5ZxX31Z55K+Ch90ybKM4ue66qYZa5XgiaRS6UThEdeReBOt0Cp92I11OwrM9HRekQ+fpO0h5rC0lN.vxxFE0bMsNyrK94lhgsjgl9s2sMgS8ZvM4Xll9spQaOrQO5EN9i+UDFokMVbSIsFff7a9IT61BDKZUamdD61GDtlYZZ5FGDaAV12BbOimQZShZO1RbWYGn3YnZOzWZZvqjJ7JN+vSWAd2xGdegQCKOhKOtGA19CFO0gi85XBaApvxerZK8uuswNTXDN706adF9IdvMQynvVEKtFZyhEWsRtrH3WtrarA5wi9CcLpgYeWabeSWzNvBsK0ifYnliYvnM1HWVXOkwQma5EOu8IL9I6r8QkPOFEBotX9Nz9tTG3lB4Gcn4E.aJxp77KqxRYIWfmSvW3R83HanODuGFQ339rbYGE.qyvfvFvvhVxuFh6M.KjynheRiLF8mgGtsmm4P.yG2rh.Iw8ctocI+1C1Gj.0c.GMvoM1CY4ayGpJOG3DBSLo70pex9CZeAoa90DW+5g+BbQi5mbjY+Vl9W95KuDtXu8NwpmGgkuYEoNh1y48HLzEvITTOvwTZSXxknuR.uMNtMp0PEfHlqDGzVmBn3MusRnDQcndnBNHhiOFWMnYwu2nbMn2iD5k4ZS3Lekx8HNcgYxoHS+8mALQKhN6RNG6fXXWSOS3DmhjDvf4BnvYcovJj+jfs6DCosW+SBW.vfYtGWrYkwLF+ktHBj+nJ0Lor.f+iXvT3fr5gsNCQ5HwWjng0josG1r8P.831Jyjzo.gUG2g3faW.LbGqBolqpZoD+FYDq6Nf0qPRLtZEAfLccwNvNGUBE7kfoSX2DlPEghsY3YoCgKURMzTpAKXEwwv1h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RFjxWWU8rMpmcu8R.tLW82aVL39mclF3dWqYCNNkZyItB6lT1Af8NFxucj2GUKourRlh3202B4ao58QQ.5KMF7JdkjKX7NuUPrf9LztY7Bu1eqfty82JXBZfgC6cUUI.F15+pZBpew5ZLr9B67yplhxW7RIEeu3NhH6EuFGgoWbWgz7haIliWbaIH34eFcDJdwi9iJ9c2EhvsQs5mTS7Ro71n3HetF2Y99bM.wcfIX.TFYMR2HU42hp2bjQWBLkuWTsEF6xO.mBWrwaWd9fq1BhNq9xpjYUORDwjMF6icAExgMrk6UMh.aXSeUUUxqWKaQo42VbC469+b4IW9284IuVL0+XbedBz7+fB04f.tg9RhTrQTvMDYGCIgan+efewrv8ycFvC2uy44YEnuTvSJH1k9J9XBtwn7SOtf+e7wEnur1+0jvzwA
                                            

                                            It is printing all values. Checkout my snippet.
                                            Console.print(val1); prints everything! yet but var attrib only has 1 item, "chris". Thats what i dont understand...

                                            Ok, will do more reading...
                                            I got other work to do, so doing this when i can
                                            Thanks!

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            40

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            101.9k

                                            Posts