hexicle
hexicle

Reputation: 2187

How to insert array into specific index of array?

I have tried the following but they don't work. I want a result like [[[arr1],[arr2],[arr3]],[[arr4],[arr5],[arr6]]].

array3[counter].push(array2[e+f]);
//Uncaught TypeError: Cannot call method 'push' of undefined 

array3.splice(counter,0,array2[e+f]);
//[Array[2], Array[3], Array[4], Array[4], Array[2], Array[3]]

Here is my source code if it helps: http://jsfiddle.net/yUXPz/

Upvotes: 1

Views: 78

Answers (1)

LameCoder
LameCoder

Reputation: 1297

If you're trying to add an array to array3 at the specified counter location then use this:

            array3[counter] = [];
            array3[counter].push(array2[e+f]);

Here is the output I got:

[
  [
    [
      7,
      8,
      9
    ]
  ],
  [
    [
      3,
      3,
      3,
      4
    ]
  ]
]

Is that what you're looking to get?

Upvotes: 2

Related Questions