0

I have two arrays,

arr1 = [1589135400000, 1589221800000, 1589308200000, 1589394600000, 1589481000000, 1589567400000, 1589653800000, 1589740200000, 1589826600000, 1591122600000]'    
arr2 = [90.05, 98.0225, 99.8231, 99.3969, 73.45, 68.356, 55.123, 100, 68.75, 98.02430  ]  

i need to form array of arrays which should look like this.

[
      [1589135400000, 90.05],
      [1589221800000, 98.0225],
      [1589308200000, 99.8231],
      [1589394600000, 99.3969],
      [1589481000000, 73.45],
      [1589567400000, 68.356],
      [1589653800000, 55.123],
      [1589740200000, 100],
      [1589826600000, 68.75],
      [1591122600000, 98.02430]

     
]

I am using typescript. please some one help me to solve this.please please Thanks in advance

2
  • Try arr1.map((v, i) => [v, arr2[i]]) Commented Jul 7, 2020 at 14:17
  • FYI, the question and the result you ask for aren't the same thing. It looks like what you want is to make an array of arrays from two arrays, in which the two arrays are mapped on the overall index o each other... Commented Jul 7, 2020 at 14:19

2 Answers 2

3

You can use array.map to combine the array values at the same index.

const arr1 = [
  1589135400000,
  1589221800000,
  1589308200000,
  1589394600000,
  1589481000000,
  1589567400000,
  1589653800000,
  1589740200000,
  1589826600000,
  1591122600000,
];

const arr2 = [
  90.05,
  98.0225,
  99.8231,
  99.3969,
  73.45,
  68.356,
  55.123,
  100,
  68.75,
  98.02430,
];

const combined = arr1.map((n, i) => [n, arr2[i]]);

console.log(combined);

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

Comments

0

Just loop over the first and find the same index in the second

arr1 = [1589135400000, 1589221800000, 1589308200000, 1589394600000, 1589481000000, 1589567400000, 1589653800000, 1589740200000, 1589826600000, 1591122600000]
arr2 = [90.05, 98.0225, 99.8231, 99.3969, 73.45, 68.356, 55.123, 100, 68.75, 98.02430 ]

console.log(arr1.map((el, i) => [ el, arr2[i] ]))

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.