HISE Logo Forum
    • Categories
    • Register
    • Login

    trying to search an array for string using indexOf() but only return exact matches

    Scheduled Pinned Locked Moved Scripting
    4 Posts 2 Posters 215 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.
    • ospfeigrpO
      ospfeigrp
      last edited by

      Do we have another way to just search for string in an array like the .find function.
      I was trying to filter certain samplemaps and populate in a combo dropdown if any element in the array started with "snare" for example.

      const var samplemaps = Sampler.getSampleMapList();
      

      the above returns all samplemaps in the samplemaps folder what i am asking is do we have a way of filtering so only all sample maps beginning with the string "snare" populate the combobox?

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

        You can use both .contains() and .indexOf() to find values in arrays.

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

        ospfeigrpO 1 Reply Last reply Reply Quote 1
        • ospfeigrpO
          ospfeigrp @d.healey
          last edited by

          @d-healey thanks

          const var samplemaps = Sampler.getSampleMapList();
          
          var test = samplemaps;
          if(test.indexOf('bas')>= 0){
            basscombo.set("items", test[test.indexOf("bas")]);
          }
          

          this will return the samplemap bass.xml on it's own. i guess i need to wrap this in a for loop. Thanks anyway i think i understand it now

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

            You could join the array into a single string and use Engine.getRegexMatches to get all matches as 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
            • First post
              Last post

            53

            Online

            1.7k

            Users

            11.7k

            Topics

            102.1k

            Posts