Announcement

Collapse
No announcement yet.

array.splice()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • array.splice()

    Why in eSignal EFS, Array.splice() does not work as expected?
    For example, I expect the following script would print out

    new Array.length = 12
    newArray = 1,2,3,4,*,5,6,7,8,9,10

    However, it seems newArray becomes empty after calling splice() to insert elements. Is it because splice() is not supported although it is listed in EFS2 developer's reference?

    - Clearpicks

    function main()
    {
    if ( getCurrentBarIndex() == -2 ) {
    myArray=[1,2,3,4,5,6,7,8,9,10];
    newArray = myArray.splice(5,0, '*');
    newArray = myArray.splice(4,0, '*');
    debugPrintln("newArray.length = " + newArray.length);
    debugPrintln("newArray = " + newArray);
    }
    }

  • #2
    Hi clearpicks,

    Try outputting myArray, since you are not removing any elements, your newArray variable will be empty.

    Steve

    Comment


    • #3
      clearpicks,

      Works as documented for me. Note it both removes and adds elements.

      Try:
      PHP Code:
      myArray=[1,2,3,4,5,6,7,8,9,10];

      debugPrintln("myArray.length = " myArray.length);
      debugPrintln("myArray = " myArray);

      debugPrintln("");
      debugPrintln("TRYING: newArray = myArray.splice(5,0, '*')");
      newArray myArray.splice(5,0'*');

      debugPrintln("myArray.length = " myArray.length);
      debugPrintln("myArray = " myArray);

      debugPrintln("NEWArray.length = " newArray.length);
      debugPrintln("NEWArray = " newArray);

      debugPrintln("");
      debugPrintln("TRYING: newArray = myArray.splice(1,2, '$')");
      newArray myArray.splice(1,2'$');

      debugPrintln("myArray.length = " myArray.length);
      debugPrintln("myArray = " myArray);

      debugPrintln("NEWArray.length = " newArray.length);
      debugPrintln("NEWArray = " newArray); 
      Output (in time order):

      myArray.length = 10
      myArray = 1,2,3,4,5,6,7,8,9,10

      TRYING: newArray = myArray.splice(5,0, '*')
      myArray.length = 11
      myArray = 1,2,3,4,5,*,6,7,8,9,10
      NEWArray.length = 0
      NEWArray =

      TRYING: newArray = myArray.splice(1,2, '$')
      myArray.length = 10
      myArray = 1,$,4,5,*,6,7,8,9,10
      NEWArray.length = 2
      NEWArray = 2,3
      Last edited by shortandlong; 01-20-2010, 11:00 AM.

      Comment


      • #4
        Hi clearpicks,

        forgot to add the link to an Array reference that has example code already written...

        http://www.hunlock.com/blogs/Masteri...ascript_Arrays

        Comment


        • #5
          Most of you who come from a software development background probably already know this but the eSignal EFS scripting is using as its base implementation a Javascript interpreter (aka SpiderMonkey) from mozilla.org. SpiderMonkey resides in the the file jsVC8.dll.

          This is why I would doubt there's any kind of serious bug in the Array logic to begin with. After all, you've got Brendan Eich, the creator of the Javascript language still overseeing that project since 1995. The level of ability of those SpiderMonkey guys is as good as it gets.

          Comment

          Working...
          X