0

I have this array:

var arrayPpal = [];

with this question I want to know how I can add the elements of other arrays to arrayPpal on the same level without having to perform cycles(without using cycle for, while.) or something like that.

var array1 = [1,2,3,4,5,6,7];
var array2 = [8,9,10];

the output should be:

arrayPpal = [1,2,3,4,5,6,7,8,9,10];

https://jsfiddle.net/m57axggp/

9
  • 4
    What did you try ? Commented Oct 10, 2017 at 14:22
  • @PrerakSola I tried this Array.prototype.push.apply(); but I want know if there is a best way. in my real project this causes a rare problem.. Commented Oct 10, 2017 at 14:23
  • Recommended reading: javascriptkit.com/jsref/arrays.shtml Commented Oct 10, 2017 at 14:24
  • 2
    What do you mean by "without cycles" ? Commented Oct 10, 2017 at 14:24
  • 2
    Just use concat method. let arrayPal=array1.concat(array2) Commented Oct 10, 2017 at 14:24

1 Answer 1

1

Use the concat method.

var arrayPpal=[];

var array1 = [1,2,3,4,5,6,7];
var array2 = [8,9,10];

arrayPpal = array1.concat(array2);

alert(arrayPpal);

Updated Fiddle

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.