{
  "id": 10329544,
  "title": "Nested Arrays in JavaScript",
  "url": "https://urgent.news/2026/09/28/nested-arrays-in-javascript",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-28T01:17:57.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/farah_ismahhana_1c67ec83/nested-arrays-in-javascript-3h68"
  },
  "original_language": "en",
  "account": "In JavaScript, arrays are commonly used to store a collection of values. While simple arrays can contain elements of the same type, sometimes it's beneficial to organize values into groups within a single array. This is achieved by creating nested arrays.\n\nA nested array consists of multiple arrays, each containing its own set of values. For instance, consider the following example:\n```javascript\nconst numbers = [ [ 10, 20, 30 ], [ 40, 50, 60 ] ];\n```\nIn this case, the `numbers` array holds two groups of numbers. Each group is an array, and both arrays are nested within the `numbers` array. To illustrate this concept further, let's examine a regular array first:\n```javascript\nconst fruits = [ \"Apple\", \"Banana\", \"Orange\" ];\nconsole.log(fruits[0]);\nconsole.log(fruits[1]);\nconsole.log(fruits[2]);\n```\nThe output of this code is:\n```\nApple\nBanana\nOrange\n```\nHere, each fruit has an index representing its position in the array. In JavaScript, the index starts at 0, so \"Apple\" is at index 0, \"Banana\" at index 1, and \"Orange\" at index 2.\n\nNow, imagine we want to split the fruits into smaller groups:\n```javascript\nconst fruits = [ [\"Apple\", \"Banana\"], [\"Orange\", \"Mango\"] ];\nconsole.log(fruits[0]);\nconsole.log(fruits[1]);\n```\nThe output becomes:\n```\n[\"Apple\", \"Banana\"]\n[\"Orange\", \"Mango\"]\n```\nIn this nested array, the outer array holds two inner arrays, each representing a group of fruits. Accessing data in a nested array requires multiple indices. For example, to access the first group of numbers, we could use:\n```javascript\nconst numbers = [ [10, 20, 30], [40, 50, 60] ];\nconsole.log(numbers[0]);\n```\nThis code outputs:\n```\n[10, 20, 30]\n```\nThe first index, `0`, retrieves the first inner array. To extract a specific value, like the number 20, we need a second index:\n```javascript\nconsole.log(numbers[0][1]);\n```\nThis line outputs:\n```\n20\n```\nBreaking it down, `numbers[0]` retrieves the first inner array `[10, 20, 30]`, and `numbers[0][1]` accesses the second value from that array, which is 20.\n\nThe concept of nested arrays can be applied to various data types. For example, grouping student names might look like this:\n```javascript\nconst students = [ [\"Hana\", \"Dini\"], [\"Khalisha\", \"Khayra\"] ];\nconsole.log(students[0][0]);\nconsole.log(students[1][1]);\n```\nThe output is:\n```\nHana\nKhayra\n```\nIn this example, `students[0][0]` retrieves the first name from the first inner array, \"Hana\". Similarly, `students[1][1]` retrieves the second name from the second inner array, \"Khayra\".\n\nTo access a value in a nested array, we start from the outermost array and progress inward with each index. The syntax `array[firstIndex][secondIndex]` allows us to navigate through multiple levels of nesting. This approach becomes more intuitive as we gain familiarity with working with nested arrays in JavaScript.",
  "summary": "Introduction When working with arrays in JavaScript, we usually start with a simple list of values. This works well when all the values belong to the same group. Sometimes, we may want to group those values while still keeping them in a single array. For example: const numbers = [ [ 10 , 20 , 30 ], [ 40 , 50 , 60 ] ]; Here, the numbers are organized into two groups. Each group is an array, and…",
  "key_points": [
    "Nested arrays contain multiple arrays within a single array",
    "Access nested array values using multiple indices",
    "Syntax: array[firstIndex][secondIndex]"
  ],
  "editors_take": "Nested arrays in JavaScript enable organizing values into groups within a single array, allowing for more complex data structures and requiring multiple indices to access specific values.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}