Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add array to two-dimensional array

Tags:

Array A is a two dimensional array. It's made up of array X and Y. I'd like to add array Z to Array A as another item in Array A. How do I do this?

Edited to add code:

arrayA = new Array(
    [1, 2, 3] //array x
    [4, 5, 6] //array y
    );

arrayZ = new Array(7, 8, 9);

//now, how do I add arrayZ onto the end of arrayA?
like image 687
dmr Avatar asked Nov 18 '11 14:11

dmr


People also ask

How do you add an array to a two dimensional array in Java?

To create a two dimensional array in Java, you have to specify the data type of items to be stored in the array, followed by two square brackets and the name of the array. Here's what the syntax looks like: data_type[][] array_name; Let's look at a code example.

How do you add two-dimensional arrays?

Syntax: data_type[1st dimension][2nd dimension][]..[Nth dimension] array_name = new data_type[size1][size2]….[sizeN];

How do you append a two dimensional array in Python?

We can insert elements into a 2 D array using the insert() function that specifies the element' index number and location to be inserted. # Write a program to insert the element into the 2D (two dimensional) array of Python. from array import * # import all package related to the array.

How do I turn an array into a 2D array?

Use reshape() Function to Transform 1d Array to 2d Array The number of components within every dimension defines the form of the array. We may add or delete parameters or adjust the number of items within every dimension by using reshaping.


1 Answers

This will add it to the end of arrayA

arrayA.push(arrayZ);

Here's a reference for push: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push

like image 119
Jonathan M Avatar answered Sep 28 '22 00:09

Jonathan M