HISE Logo Forum
    • Categories
    • Register
    • Login

    Get the number of elements in a JSON object

    Scheduled Pinned Locked Moved General Questions
    9 Posts 3 Posters 146 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.
    • JulesVJ
      JulesV
      last edited by

      This is a very basic question but I'm asking because I really can't find it.

      How can we find the length of an object containing a string and color pair data like the one below?

      NOTE: Of course, Select.length doesn't work here.

      const Select = 
      {
      							"Alien": 0xFF651313,
      							"Cow": 0xFF291bdf,
      							"Bird": 0xFF20df1b,
      							"Shark": 0xFF77650e	
      };
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @JulesV
        last edited by d.healey

        @JulesV You need to run a loop over the object.

        reg count = 0;
        
        for (x in Select)
            count++;
        
        Console.print(count);
        

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

        JulesVJ 1 Reply Last reply Reply Quote 1
        • JulesVJ
          JulesV @d.healey
          last edited by JulesV

          @d-healey You've saved me, Thank you!

          Can I ask you one last thing?

          If I use this in a 2D array format like below, How can I create the ComboBox list with strings that are the first value of each array [0]?

          const Select = 
          [
          		["Alien", 0xFF651313],
          		["Cow", 0xFF291bdf],
          		["Bird", 0xFF20df1b],
          		["Shark", 0xFF77650e]								
          ];
          
          
          const var ComboBox1 = Content.getComponent("ComboBox1");
          ComboBox1.set("items", Select.join("\n"));
          
          
          
          

          NOTE: I tried to add this in a loop, but it doesn't work.

          for (i = 0; i < Select.length; i++)
          {
              ComboBox1.set("items", Select[i][0].join("\n")); 
          }
          
          d.healeyD A 2 Replies Last reply Reply Quote 0
          • d.healeyD
            d.healey @JulesV
            last edited by

            @JulesV Do you mean you want the combo box to have the values Alien, Cow, Bird, Shark? Or do you want each of those in a separate combo box?

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

            JulesVJ 1 Reply Last reply Reply Quote 0
            • JulesVJ
              JulesV @d.healey
              last edited by

              @d-healey Yes, the combo box to have the values Alien, Cow, Bird, Shark.

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

                @JulesV

                ComboBox1.setItems(""); // Clear the items
                
                for (x in Select)
                    ComboBox1.addItem(x[0]); // Add the items
                

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

                JulesVJ 1 Reply Last reply Reply Quote 1
                • JulesVJ
                  JulesV @d.healey
                  last edited by

                  @d-healey I got it, Thank you sir!

                  1 Reply Last reply Reply Quote 0
                  • A
                    aaronventure @JulesV
                    last edited by

                    @JulesV https://forum.hise.audio/topic/10825/secret-array-sort-function-argument-lets-you-sort-an-array-of-objects-by-a-property?_=1744962238817

                    Might be of interest to you

                    JulesVJ 1 Reply Last reply Reply Quote 1
                    • JulesVJ
                      JulesV @aaronventure
                      last edited by

                      @aaronventure Thanks, looks interesting :)

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

                      50

                      Online

                      1.7k

                      Users

                      11.7k

                      Topics

                      102.1k

                      Posts