# How do I make a 2 dimensional array?

**URL:** <https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934>\
**Category:** Coding Questions\
**Created:** [December 3, 2020, 3:56pm UTC](https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934 "2020-12-03T15:56:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MisledWater079](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@MisledWater079](https://discourse.processing.org/u/MisledWater079)\
**Post date:** [December 3, 2020, 3:56pm UTC](https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934/1 "2020-12-03T15:56:16Z")

</div>

I’m watching a Coding Train video “ Coding Challenge #11: 3D Terrain Generation with Perlin Noise in Processing” and he uses float[][]; and it doesn’t work on p5.js and I was wondering if they changed it and what I can use as a alternative.

---

<div class="post-metadata">

**Author:** ![Mesalcode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mesalcode/32/9284_2.png) [@Mesalcode](https://discourse.processing.org/u/Mesalcode)\
**Post date:** [December 3, 2020, 4:15pm UTC](https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934/2 "2020-12-03T16:15:37Z")

</div>

If the tutorial you are referring to is in java and you just tried to use the same code in p5.js it won’t work. Javascript and Java are fundamentely different. If you don’t want to learn a new programming language, but still program for the web using processing, I’d suggest using [Processing.JS](https://happycoding.io/tutorials/processing/processing-js#processingjs) which allows you to use Java Processing in web applications.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [December 3, 2020, 4:21pm UTC](https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934/3 "2020-12-03T16:21:41Z")

</div>

Arrays in Java and Javascript are very different this example creates a 2D 10x10 array

```auto
var table = new Array(10);
for(var i = 0; i < table.length; i++)
  table[i] = new Array(10);

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 3, 2020, 5:05pm UTC](https://discourse.processing.org/t/how-do-i-make-a-2-dimensional-array/25934/4 "2020-12-03T17:05:46Z")

</div>

> [@MisledWater079](#):
>
> Coding Challenge #11: 3D Terrain Generation with Perlin Noise

> **[3D Terrain Generation with Perlin Noise](https://thecodingtrain.com/challenges/11-3d-terrain-generation-with-perlin-noise/)**
>
> Let's fly to new heights with a 3D terrain coding challenge! Using Perlin Noise and beginShape() + endShape() with triangle strips, I'll guide you through visualizing a 3D procedural terrain in Processing.

> [@MisledWater079](#):
>
> … and he uses `float[][]` and it doesn’t work on p5.js…

```javascript
function createFloatArray2d(rows, cols) {
  return Array.from({ length: rows }, _ => new Float32Array(cols));
}

```

> **[Array.from() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)**
>
> The Array.from() static method creates a new, shallow-copied Array instance from an iterable or array-like object.

> **[Float32Array - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)**
>
> The Float32Array typed array represents an array of 32-bit floating point numbers in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0. Once established, you can reference elements...
