-2

Suppose we have two arrays

var arrayOne = [21.03.2016, 22.03.2016, 23.03.2016]
var arrayTwo = [23.45, 34.45, 25.76]

How can we join it so that it becomes

var joinedResultOfOneandTwo = [[21.03.2016, 23.45], 
                               [22.03.2016, 34.45],
                               [23.03.2016, 25.76]]

Note It is important that we do not change the type of variables both of them should be numbers.

This is what I have tried:

for (var i = 0; i < arrayOne.length; i++) {
            var clintonValues = arrayOne[i].concat(arrayTwo[i])

          }

returns:

TypeError: arrayOne[i].concat is not a function

Imi
  • 529
  • 2
  • 8
  • 23

2 Answers2

2

Here is an example

var arrayOne = ['21.03.2016', '22.03.2016', '23.03.2016']
var arrayTwo = ['23.45', '34.45', '25.76']
var joinedResultOfOneandTwo = [];

for (i = 0; i < arrayOne.length; i++) {
  joinedResultOfOneandTwo.push([arrayOne[i], arrayTwo[i]]);
}

console.log(joinedResultOfOneandTwo);
Pugazh
  • 9,453
  • 5
  • 33
  • 54
-1

Did you try .concat? It will join two arrays into one
var arrayOne = [21.03.2016, 22.03.2016, 23.03.2016]; var arrayTwo = [23.45, 34.45, 25.76]; arrayOne.concat(arrayTwo);//join arrayTwo into arrayOne

Krzysztof Borowy
  • 538
  • 1
  • 5
  • 21