How would you append to a two array and append to a certain rows.
like
a = [1,2,3]
b = [5,6]
then you append a to the first column and b to the second column of another array so it would be
c =
[1,2,3]
[5,6]
hope this makes sense and thanks in advance
Processing
<datatype> <name>[] = new <datatype>[length (integer)];
int w = 10, h = 10;
int grid[][] = new int[w][h];
grid[0][3] = 3;
you need to determin the size of the array
let a = []; //i don't really know the syntax
let w = 10, h = 10; //set length of a[] to w*h
function access(int input1, int input2) {
return( a[input1 + input2*w]);
}
You’ve added the p5.js tag to this question.
In JavaScript, you can directly use the push method to append any data to an existing array.
For example,
let a = [1, 2, 3];
let b = [4,5];
let c = [ ];
c.push(a); //c = [[1,2,3]] now
c.push(b); //c = [[1,2,3], [4,5]] now
Using the []
syntax for creating arrays is common in JS.
And there are many other ways to do that for 2D arrays.
Here’s 1 you can copy & paste on any browser console or even Node.js:
var a = Uint8Array.of(1, 2, 3), b = Uint8Array.of(5, 6);
console.info(a, b);
var c = [ a, b ];
console.table(c);
And the corresponding Processing’s Java Mode version for 2D arrays:
byte[] a = { 1, 2, 3 }, b = { 5, 6 };
println(a);
println();
println(b);
println();
byte[][] c = { a, b };
for (byte[] row : c) println(str(row));
exit();
And Python Mode version as well:
a = 1, 2, 3
b = 5, 6
print a, b
c = a, b
print c
exit()
You can use the concat() method to merge the 2 arrays.
let a = [1, 2, 3];
let b = [5, 6];
a.concat(a, b);