HISE Logo Forum
    • Categories
    • Register
    • Login

    Searching arrays

    Scheduled Pinned Locked Moved Scripting
    3 Posts 2 Posters 703 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.
    • d.healeyD
      d.healey
      last edited by

      I think it's important to have the ability to search arrays, I couldn't find a function in HISE's implementation of JS to do this so I rolled my own indexOf function and attached it to the array type but I think a native solution would be better.

      if (!Array.indexOf)
      {
      	Array.indexOf = function(obj, from, typeStrict)
      	{
      	    if (fromIndex == null)
      	    {
      	        fromIndex = 0;
      	    }
      	    else if (fromIndex < 0)
      	    {
      	        fromIndex = Math.max(0, this.length + fromIndex);
      	    }
      
      	  	for (var j = from; j < this.length; j++)
      	    {
      	    	if (typeStrict == true)
      	    	{
      				if (this[j] === obj) return j;
      	    	}
      
      	        if (this[j] == obj) return j;
      	    }
      
      	    return -1;
      	};
      }
      

      HISE didn't like it when I used something like this for my for loop, although it is in the JavaScript tutorial

      for (var j = from, len = this.length; j < len;  j++)
      

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

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by Christoph Hart

        Thanks for spotting this. The problem is that by introducing the for … in loop, I accidentally broke support for multiple initialisers and fixing this is not trivial.

        But I added a native indexOf() method. While I was at it, I also added a clean Array.isArray() method...

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

          :D you're the man!

          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

          46

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts