0

I have these arrays:

arr1 = ['29.5',  32035];
arr2 = ['30.5',  32288];
arr3 = ['31.5',  31982];
arr4 = ['1.6',  31768];

As a result I want to have something like this:

result = [['29.5',  32035], ['30.5',  32288], ['31.5',  31982], ['1.6',  31768]];

I means the result is array created by another arrays. The question is, how I can concat the arrays. result.push.apply(result, arr1); etc. give me array made by final values.

Thank you for any advice.

2
  • just do result.push(arr1); and do that for each arr1 you got. And i mean 1,2,3,4 Commented Jun 8, 2017 at 9:57
  • 1
    linked "dupe" doesn't really answer this Commented Jun 8, 2017 at 10:03

2 Answers 2

3

Actually you can just do

var result = [arr1, arr2, arr3, arr4];

Or

var result = [];
result[0] = arr1;
result[1] = arr2;
result[2] = arr3;
result[3] = arr4;

Or

var result = [];
result.push(arr1);
result.push(arr2);
result.push(arr3);
result.push(arr4);
Sign up to request clarification or add additional context in comments.

Comments

2

You can do this using push .

var result = [];

result.push(arr1);
result.push(arr2);
result.push(arr3);
result.push(arr4);

console.log(result);

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.