Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 5 of 5

Thread: merging two arrays in JS

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Location
    Poland
    Posts
    680

    Default merging two arrays in JS

    Hi,

    does anyone know the simplier way in JS to merge two arrays then doing it row by row? The simple arrays like the ones with txt data from text areas.

    regards
    Artur

  2. #2
    Senior Member glg's Avatar
    Join Date
    Aug 2004
    Location
    Chicago, IL, USA
    Posts
    714

    Default

    the concat method should work for this.

  3. #3

    Default

    What exacatly do you ant to merge?
    The contents of Arrayelemts or something like Array1+=Array2 ??

  4. #4
    Senior Member
    Join Date
    Apr 2006
    Location
    Poland
    Posts
    680

    Default

    Hi,

    I have two fields - both as arrays. I want to merge them in one variable.
    With calculations it is easy: $var1 + $var2
    but in JS I had to finally do the row by row:
    var1.push(a[i]);

    I wanted something else to make it faster.
    Nothing worked well, except push()

    regards
    Artur

  5. #5
    Senior Member mateuszk's Avatar
    Join Date
    Nov 2006
    Posts
    302

    Default

    You mean something like that?

    Code:
    var a = [1,2,3];
    var b = [4,5,6];
    a = a.concat(b);

    Of course, the best way in SC/SM would be using system.functions.insert()
    but pure JS works OK.

    BTW, speaking about "faster", the code you wrote - in SC/SM terms -
    is as fast as Array.concat(), so no worries there.
    Last edited by mateuszk; 2009-03-13 at 21:08.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts