Forum

    • Register
    • Login
    • Search
    • Categories

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

    Scripting Forum
    2
    4
    101
    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.
    • ospfeigrp
      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.healey
        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

        ospfeigrp 1 Reply Last reply Reply Quote 1
        • ospfeigrp
          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.healey
            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

            5
            Online

            1.2k
            Users

            7.0k
            Topics

            64.8k
            Posts