-7

I have two arrays:

var array1= [[1],[2],[3]];
var array2= [[10],[20],[30]];

is there a way to (have) a third array?

var array3 = [[1],[10],[2],[20],[3],[30]]; 

Maybe:

var test= array1.join(array2 + "<br>");
1
  • 1
    Question marks: 1 or 0, not an arbitrary number. Commented Jul 12, 2014 at 22:56

2 Answers 2

3

I think you are looking for the "concat" function

Join two arrays:

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

The values of the children array will be:

Cecilie,Lone,Emil,Tobias,Linus

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

Sign up to request clarification or add additional context in comments.

12 Comments

no concat.... combine. In yuor case, i want "celie, emil, lone, tobias.
Note, if want to do a safe concat you'd do hege.concat([stale])
@elclanrs: That would give an undesirable result. ["Cecilie", "lone", ["Emil", "Tobias", "Linus"]]
@cookiemonster: right... I was thinking of a different case. concat has some gotchas...
@user3163117: Oh, you want it zipped. Simple enough with a loop. Start writing some code.
|
0

You can either use CONCAT function like

array1 = array1.concat(array2)

OR, APPLY()

array1.push.apply(array1, array2)

2 Comments

not function, and it is not a "concat" the true way.... :/
You say so cause probably the order in which the items to be as in your posted code. Right? You can use a for loop and get the item combined but I am not sure about the order though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.