Forum Discussion

abjoe's avatar
abjoe
New Contributor II
8 years ago

Create array using script snap

Hi Everyone,

I have written a simple javascript code in Script snap. Please find the code below:

script = {
execute : function()
{
while (input.hasNext())
{
var test = [“a”, “b”];

                 try
                  {
                        output.write(test);
                  }
                catch(err)
                  {
                        new_data.errMsg = err.message;
                        new_data.tryBlock = "failed";
                        error.write(new_data);
                  }
                  
            }
        }   
    };

var hook = new com.snaplogic.scripting.language.ScriptHook(script)

I am basically just creating an array with values [“a”, “b”] and printing it. Please find the output below:

But in the output, you can see that it has become an object {0:a, 1:b} with keys as “0” and “1”. Please help me with this. How can I get an array [“a”, “b”] as the output?

3 Replies

No RepliesBe the first to reply