trying to search an array for string using indexOf() but only return exact matches
-
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?
-
You can use both
.contains()
and.indexOf()
to find values in arrays. -
@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
-
You could join the array into a single string and use
Engine.getRegexMatches
to get all matches as an array.