-1

Possible Duplicate:
How to merge two arrays in Javascript

Let's suppose I have 2 arrays:

a = ['a','b','c'];
b = ['d','e','f'];

Is there somehow to easy add the b into a without having to split and perform an each for adding the elements?

Something like:

a.push(b);

And have an final a array with the content:

a = ['a','b','c','d','e','f'] 
4
  • 2
  • Thank you for the down votes, guys. :/
    – Kleber S.
    Commented Sep 19, 2012 at 14:42
  • @kle - One of the reasons for downvoting is a lack of research. There is nothing wrong with your actual post. The problem is that with one simple search you wouldn't have had to ask this in the first place. It's nothing personal :)
    – Lix
    Commented Sep 19, 2012 at 14:45
  • I did search but since I'm not a english speaker, I haven't remembered about the term 'merge'. No problem! :)
    – Kleber S.
    Commented Sep 19, 2012 at 14:49

2 Answers 2

6

Have you tryied the concat() function?

var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale,kai);

Will output:

Cecilie,Lone,Emil,Tobias,Linus,Robin
2
2

Use Array.concat:

a = a.concat(b); // a == ['a','b','c','d','e','f']

Not the answer you're looking for? Browse other questions tagged or ask your own question.