HISE Logo Forum
    • Categories
    • Register
    • Login

    Alternative for ".shift()" for arrays?

    Scheduled Pinned Locked Moved Scripting
    6 Posts 3 Posters 399 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.
    • Alex ParadisA
      Alex Paradis
      last edited by

      Hi everyone,

      Is there an alternative for using the function ".shift()", which removes the first element in an array?

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

        var fruits = ["Banana", "Orange", "Apple", "Mango"];
        fruits.remove(fruits[0]);
        

        Free HISE Bootcamp Full Course for beginners.
        YouTube Channel - Public HISE tutorials
        My Patreon - HISE tutorials

        Alex ParadisA 1 Reply Last reply Reply Quote 0
        • Alex ParadisA
          Alex Paradis @d.healey
          last edited by

          @d-healey said in Alternative for ".shift()" for arrays?:

          fruits.remove(fruits[0]);

          I was trying to remove the item only by its index...

          Works like a charm now. Thanks!

          LindonL 1 Reply Last reply Reply Quote 0
          • LindonL
            Lindon @Alex Paradis
            last edited by

            @Alex-Paradis please take some time with this sort of thing to check things like this:

            https://www.w3schools.com/jsref/jsref_obj_array.asp

            HISE Development for hire.
            www.channelrobot.com

            Alex ParadisA 1 Reply Last reply Reply Quote 0
            • Alex ParadisA
              Alex Paradis @Lindon
              last edited by

              @Lindon
              In fact, this is where I found the function and saw that code.

              var fruits = ["Banana", "Orange", "Apple", "Mango"];
              fruits.shift();
              

              I didn't know that for Hise you also have to add the array plus its index in the "remove()" function but anyway, it's all good for now.

              LindonL 1 Reply Last reply Reply Quote 0
              • LindonL
                Lindon @Alex Paradis
                last edited by

                @Alex-Paradis then you probably also saw this one:

                https://www.w3schools.com/jsref/jsref_splice.asp

                HISE Development for hire.
                www.channelrobot.com

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

                17

                Online

                2.0k

                Users

                12.7k

                Topics

                110.0k

                Posts