Menu
Coddy logo textTech

2D Arrays Basics

Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 6 of 65.

A 2D array is an array containing sub-arrays. Each sub-array can be seen as a row in a grid.

For example:

const cinema = [
  [true,  true],  // Row 0
  [false, true]   // Row 1
];

This array represents a 2x2 grid (2 items in each row, and there are 2 rows)

To create a 2D array of integers with 3 rows and 4 columns, you would write:

const matrix = [
	[1,  2,  3,  4],
	[5,  6,  7,  8],
	[9, 10, 11, 12]
];
// 3x4 grid
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

Cheat sheet

A 2D array is an array containing sub-arrays, where each sub-array represents a row in a grid:

const cinema = [
  [true,  true],  // Row 0
  [false, true]   // Row 1
];
// 2x2 grid
const matrix = [
	[1,  2,  3,  4],
	[5,  6,  7,  8],
	[9, 10, 11, 12]
];
// 3x4 grid (3 rows, 4 columns)

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Logic & Flow