A 1D array is a line of elements (like a queue). A 2D array is a grid of rows and columns (like a chessboard or Excel sheet). A 2D array is conceptually an 'array of arrays' — each row is itself an array.
1D: A todo list — [Buy milk, Call mom, Finish report]. 2D: A chessboard — 8 rows × 8 columns. To get the piece at row 2, column 5, you use board[2][5].
One index: arr[i]
Two indices: arr[row][col] — like Excel!
1// Chess board: 8 rows, 8 columns2let board = [3['R','N','B','Q','K','B','N','R'], // row 04['P','P','P','P','P','P','P','P'], // row 15// ...6];78board[0][0] // 'R' (top-left)9board[1][4] // 'P' (row 1, col 4)10// 2D = array of arrays
1D Array — The Line
A single row of slots. Like a queue of people or a bookshelf. You need one index: arr[i].
2D Array — The Grid
Rows and columns. Like a spreadsheet or chessboard. You need two indices: arr[row][col]. In memory, 2D arrays are often stored as one long block: row 0 first, then row 1, then row 2... The formula for position becomes: base + (row × cols + col).
Why 2D = Array of Arrays?
In many languages, a 2D array is literally an array where each element is another array. So matrix[1] gives you the second row (a 1D array), and matrix[1][2] gives you the third element of that row.
Common Uses
1D arrays are everywhere: lists, buffers, strings (as char arrays). 2D arrays model matrices, images (pixels), game boards, and spreadsheets. Knowing both is essential for real programs.
"A spreadsheet is best modeled as?"
A 2D array — rows and columns of cells.