Preliminaries

JavaScript has only one data type which can contain multiple values: Object. An Array is a special form of object.

(Plain) Objects have the form

{key: value, key: value, ...}

Arrays have the form

[value, value, ...]

Both arrays and objects expose a key -> value structure. Keys in an array must be numeric, whereas any string can be used as key in objects. The key-value pairs are also called the "properties".

Properties can be accessed either using dot notation

const value = obj.someProperty;

or bracket notation, if the property name would not be a valid JavaScript identifier name [spec], or the name is the value of a variable:

// the space is not a valid character in identifier names
const value = obj["some Property"];

// property name as variable
const name = "some Property";
const value = obj[name];

For that reason, array elements can only be accessed using bracket notation:

const value = arr[5]; // arr.5 would be a syntax error

// property name / index as variable
const x = 5;
const value = arr[x];

Wait... what about JSON?

JSON is a textual representation of data, just like XML, YAML, CSV, and others. To work with such data, it first has to be converted to JavaScript data types, i.e. arrays and objects (and how to work with those was just explained). How to parse JSON is explained in the question Parse JSON in JavaScript? .

Further reading material

How to access arrays and objects is fundamental JavaScript knowledge and therefore it is advisable to read the MDN JavaScript Guide, especially the sections

  • Working with Objects
  • Arrays
  • Eloquent JavaScript - Data Structures


Accessing nested data structures

A nested data structure is an array or object which refers to other arrays or objects, i.e. its values are arrays or objects. Such structures can be accessed by consecutively applying dot or bracket notation.

Here is an example:

const data = {
    code: 42,
    items: [{
        id: 1,
        name: 'foo'
    }, {
        id: 2,
        name: 'bar'
    }]
};

Let's assume we want to access the name of the second item.

Here is how we can do it step-by-step:

As we can see data is an object, hence we can access its properties using dot notation. The items property is accessed as follows:

data.items

The value is an array, to access its second element, we have to use bracket notation:

data.items[1]

This value is an object and we use dot notation again to access the name property. So we eventually get:

const item_name = data.items[1].name;

Alternatively, we could have used bracket notation for any of the properties, especially if the name contained characters that would have made it invalid for dot notation usage:

const item_name = data['items'][1]['name'];

I'm trying to access a property but I get only undefined back?

Most of the time when you are getting undefined, the object/array simply doesn't have a property with that name.

const foo = {bar: {baz: 42}};
console.log(foo.baz); // undefined

Use console.log or console.dir and inspect the structure of object / array. The property you are trying to access might be actually defined on a nested object / array.

console.log(foo.bar.baz); // 42

What if the property names are dynamic and I don't know them beforehand?

If the property names are unknown or we want to access all properties of an object / elements of an array, we can use the for...in [MDN] loop for objects and the for [MDN] loop for arrays to iterate over all properties / elements.

Objects

To iterate over all properties of data, we can iterate over the object like so:

for (const prop in data) {
    // `prop` contains the name of each property, i.e. `'code'` or `'items'`
    // consequently, `data[prop]` refers to the value of each property, i.e.
    // either `42` or the array
}

Depending on where the object comes from (and what you want to do), you might have to test in each iteration whether the property is really a property of the object, or it is an inherited property. You can do this with Object#hasOwnProperty [MDN].

As alternative to for...in with hasOwnProperty, you can use Object.keys [MDN] to get an array of property names:

Object.keys(data).forEach(function(prop) {
  // `prop` is the property name
  // `data[prop]` is the property value
});

Arrays

To iterate over all elements of the data.items array, we use a for loop:

for(let i = 0, l = data.items.length; i < l; i++) {
    // `i` will take on the values `0`, `1`, `2`,..., i.e. in each iteration
    // we can access the next element in the array with `data.items[i]`, example:
    // 
    // var obj = data.items[i];
    // 
    // Since each element is an object (in our example),
    // we can now access the objects properties with `obj.id` and `obj.name`. 
    // We could also use `data.items[i].id`.
}

One could also use for...in to iterate over arrays, but there are reasons why this should be avoided: Why is 'for(var item in list)' with arrays considered bad practice in JavaScript?.

With the increasing browser support of ECMAScript 5, the array method forEach [MDN] becomes an interesting alternative as well:

data.items.forEach(function(value, index, array) {
    // The callback is executed for each element in the array.
    // `value` is the element itself (equivalent to `array[index]`)
    // `index` will be the index of the element in the array
    // `array` is a reference to the array itself (i.e. `data.items` in this case)
}); 

In environments supporting ES2015 (ES6), you can also use the for...of [MDN] loop, which not only works for arrays, but for any iterable:

for (const item of data.items) {
   // `item` is the array element, **not** the index
}

In each iteration, for...of directly gives us the next element of the iterable, there is no "index" to access or use.


What if the "depth" of the data structure is unknown to me?

In addition to unknown keys, the "depth" of the data structure (i.e. how many nested objects) it has, might be unknown as well. How to access deeply nested properties usually depends on the exact data structure.

But if the data structure contains repeating patterns, e.g. the representation of a binary tree, the solution typically includes to recursively [Wikipedia] access each level of the data structure.

Here is an example to get the first leaf node of a binary tree:

function getLeaf(node) {
    if (node.leftChild) {
        return getLeaf(node.leftChild); // <- recursive call
    }
    else if (node.rightChild) {
        return getLeaf(node.rightChild); // <- recursive call
    }
    else { // node must be a leaf node
        return node;
    }
}

const first_leaf = getLeaf(root);

const root = {
    leftChild: {
        leftChild: {
            leftChild: null,
            rightChild: null,
            data: 42
        },
        rightChild: {
            leftChild: null,
            rightChild: null,
            data: 5
        }
    },
    rightChild: {
        leftChild: {
            leftChild: null,
            rightChild: null,
            data: 6
        },
        rightChild: {
            leftChild: null,
            rightChild: null,
            data: 7
        }
    }
};
function getLeaf(node) {
    if (node.leftChild) {
        return getLeaf(node.leftChild);
    } else if (node.rightChild) {
        return getLeaf(node.rightChild);
    } else { // node must be a leaf node
        return node;
    }
}

console.log(getLeaf(root).data);

A more generic way to access a nested data structure with unknown keys and depth is to test the type of the value and act accordingly.

Here is an example which adds all primitive values inside a nested data structure into an array (assuming it does not contain any functions). If we encounter an object (or array) we simply call toArray again on that value (recursive call).

function toArray(obj) {
    const result = [];
    for (const prop in obj) {
        const value = obj[prop];
        if (typeof value === 'object') {
            result.push(toArray(value)); // <- recursive call
        }
        else {
            result.push(value);
        }
    }
    return result;
}

const data = {
  code: 42,
  items: [{
    id: 1,
    name: 'foo'
  }, {
    id: 2,
    name: 'bar'
  }]
};


function toArray(obj) {
  const result = [];
  for (const prop in obj) {
    const value = obj[prop];
    if (typeof value === 'object') {
      result.push(toArray(value));
    } else {
      result.push(value);
    }
  }
  return result;
}

console.log(toArray(data));



Helpers

Since the structure of a complex object or array is not necessarily obvious, we can inspect the value at each step to decide how to move further. console.log [MDN] and console.dir [MDN] help us doing this. For example (output of the Chrome console):

> console.log(data.items)
 [ Object, Object ]

Here we see that that data.items is an array with two elements which are both objects. In Chrome console the objects can even be expanded and inspected immediately.

> console.log(data.items[1])
  Object
     id: 2
     name: "bar"
     __proto__: Object

This tells us that data.items[1] is an object, and after expanding it we see that it has three properties, id, name and __proto__. The latter is an internal property used for the prototype chain of the object. The prototype chain and inheritance is out of scope for this answer, though.

🌐
DEV Community
dev.to › flexdinesh › accessing-nested-objects-in-javascript--9m4
Accessing Nested Objects in JavaScript - DEV Community
April 7, 2018 - This way, the next level key will always be accessed from an object that exists or an empty object, but never from undefined. Unfortunately, you cannot access nested arrays with this trick · Array reduce method is very powerful and it can be used to safely access nested objects.
Top answer
1 of 16
1474

Preliminaries

JavaScript has only one data type which can contain multiple values: Object. An Array is a special form of object.

(Plain) Objects have the form

{key: value, key: value, ...}

Arrays have the form

[value, value, ...]

Both arrays and objects expose a key -> value structure. Keys in an array must be numeric, whereas any string can be used as key in objects. The key-value pairs are also called the "properties".

Properties can be accessed either using dot notation

const value = obj.someProperty;

or bracket notation, if the property name would not be a valid JavaScript identifier name [spec], or the name is the value of a variable:

// the space is not a valid character in identifier names
const value = obj["some Property"];

// property name as variable
const name = "some Property";
const value = obj[name];

For that reason, array elements can only be accessed using bracket notation:

const value = arr[5]; // arr.5 would be a syntax error

// property name / index as variable
const x = 5;
const value = arr[x];

Wait... what about JSON?

JSON is a textual representation of data, just like XML, YAML, CSV, and others. To work with such data, it first has to be converted to JavaScript data types, i.e. arrays and objects (and how to work with those was just explained). How to parse JSON is explained in the question Parse JSON in JavaScript? .

Further reading material

How to access arrays and objects is fundamental JavaScript knowledge and therefore it is advisable to read the MDN JavaScript Guide, especially the sections

  • Working with Objects
  • Arrays
  • Eloquent JavaScript - Data Structures


Accessing nested data structures

A nested data structure is an array or object which refers to other arrays or objects, i.e. its values are arrays or objects. Such structures can be accessed by consecutively applying dot or bracket notation.

Here is an example:

const data = {
    code: 42,
    items: [{
        id: 1,
        name: 'foo'
    }, {
        id: 2,
        name: 'bar'
    }]
};

Let's assume we want to access the name of the second item.

Here is how we can do it step-by-step:

As we can see data is an object, hence we can access its properties using dot notation. The items property is accessed as follows:

data.items

The value is an array, to access its second element, we have to use bracket notation:

data.items[1]

This value is an object and we use dot notation again to access the name property. So we eventually get:

const item_name = data.items[1].name;

Alternatively, we could have used bracket notation for any of the properties, especially if the name contained characters that would have made it invalid for dot notation usage:

const item_name = data['items'][1]['name'];

I'm trying to access a property but I get only undefined back?

Most of the time when you are getting undefined, the object/array simply doesn't have a property with that name.

const foo = {bar: {baz: 42}};
console.log(foo.baz); // undefined

Use console.log or console.dir and inspect the structure of object / array. The property you are trying to access might be actually defined on a nested object / array.

console.log(foo.bar.baz); // 42

What if the property names are dynamic and I don't know them beforehand?

If the property names are unknown or we want to access all properties of an object / elements of an array, we can use the for...in [MDN] loop for objects and the for [MDN] loop for arrays to iterate over all properties / elements.

Objects

To iterate over all properties of data, we can iterate over the object like so:

for (const prop in data) {
    // `prop` contains the name of each property, i.e. `'code'` or `'items'`
    // consequently, `data[prop]` refers to the value of each property, i.e.
    // either `42` or the array
}

Depending on where the object comes from (and what you want to do), you might have to test in each iteration whether the property is really a property of the object, or it is an inherited property. You can do this with Object#hasOwnProperty [MDN].

As alternative to for...in with hasOwnProperty, you can use Object.keys [MDN] to get an array of property names:

Object.keys(data).forEach(function(prop) {
  // `prop` is the property name
  // `data[prop]` is the property value
});

Arrays

To iterate over all elements of the data.items array, we use a for loop:

for(let i = 0, l = data.items.length; i < l; i++) {
    // `i` will take on the values `0`, `1`, `2`,..., i.e. in each iteration
    // we can access the next element in the array with `data.items[i]`, example:
    // 
    // var obj = data.items[i];
    // 
    // Since each element is an object (in our example),
    // we can now access the objects properties with `obj.id` and `obj.name`. 
    // We could also use `data.items[i].id`.
}

One could also use for...in to iterate over arrays, but there are reasons why this should be avoided: Why is 'for(var item in list)' with arrays considered bad practice in JavaScript?.

With the increasing browser support of ECMAScript 5, the array method forEach [MDN] becomes an interesting alternative as well:

data.items.forEach(function(value, index, array) {
    // The callback is executed for each element in the array.
    // `value` is the element itself (equivalent to `array[index]`)
    // `index` will be the index of the element in the array
    // `array` is a reference to the array itself (i.e. `data.items` in this case)
}); 

In environments supporting ES2015 (ES6), you can also use the for...of [MDN] loop, which not only works for arrays, but for any iterable:

for (const item of data.items) {
   // `item` is the array element, **not** the index
}

In each iteration, for...of directly gives us the next element of the iterable, there is no "index" to access or use.


What if the "depth" of the data structure is unknown to me?

In addition to unknown keys, the "depth" of the data structure (i.e. how many nested objects) it has, might be unknown as well. How to access deeply nested properties usually depends on the exact data structure.

But if the data structure contains repeating patterns, e.g. the representation of a binary tree, the solution typically includes to recursively [Wikipedia] access each level of the data structure.

Here is an example to get the first leaf node of a binary tree:

function getLeaf(node) {
    if (node.leftChild) {
        return getLeaf(node.leftChild); // <- recursive call
    }
    else if (node.rightChild) {
        return getLeaf(node.rightChild); // <- recursive call
    }
    else { // node must be a leaf node
        return node;
    }
}

const first_leaf = getLeaf(root);

const root = {
    leftChild: {
        leftChild: {
            leftChild: null,
            rightChild: null,
            data: 42
        },
        rightChild: {
            leftChild: null,
            rightChild: null,
            data: 5
        }
    },
    rightChild: {
        leftChild: {
            leftChild: null,
            rightChild: null,
            data: 6
        },
        rightChild: {
            leftChild: null,
            rightChild: null,
            data: 7
        }
    }
};
function getLeaf(node) {
    if (node.leftChild) {
        return getLeaf(node.leftChild);
    } else if (node.rightChild) {
        return getLeaf(node.rightChild);
    } else { // node must be a leaf node
        return node;
    }
}

console.log(getLeaf(root).data);

A more generic way to access a nested data structure with unknown keys and depth is to test the type of the value and act accordingly.

Here is an example which adds all primitive values inside a nested data structure into an array (assuming it does not contain any functions). If we encounter an object (or array) we simply call toArray again on that value (recursive call).

function toArray(obj) {
    const result = [];
    for (const prop in obj) {
        const value = obj[prop];
        if (typeof value === 'object') {
            result.push(toArray(value)); // <- recursive call
        }
        else {
            result.push(value);
        }
    }
    return result;
}

const data = {
  code: 42,
  items: [{
    id: 1,
    name: 'foo'
  }, {
    id: 2,
    name: 'bar'
  }]
};


function toArray(obj) {
  const result = [];
  for (const prop in obj) {
    const value = obj[prop];
    if (typeof value === 'object') {
      result.push(toArray(value));
    } else {
      result.push(value);
    }
  }
  return result;
}

console.log(toArray(data));



Helpers

Since the structure of a complex object or array is not necessarily obvious, we can inspect the value at each step to decide how to move further. console.log [MDN] and console.dir [MDN] help us doing this. For example (output of the Chrome console):

> console.log(data.items)
 [ Object, Object ]

Here we see that that data.items is an array with two elements which are both objects. In Chrome console the objects can even be expanded and inspected immediately.

> console.log(data.items[1])
  Object
     id: 2
     name: "bar"
     __proto__: Object

This tells us that data.items[1] is an object, and after expanding it we see that it has three properties, id, name and __proto__. The latter is an internal property used for the prototype chain of the object. The prototype chain and inheritance is out of scope for this answer, though.

2 of 16
108

You can access it this way

data.items[1].name

or

data["items"][1]["name"]

Both ways are equal.

Discussions

How to access multiple nested objects when the nested object name is variable
I may not be using terminology correctly in the way I’m describing this so hopefully it makes sense. The issue I’m having is I believe I have a js response where there is an object nested within an object, but it is not an array. I want to access a property called sellerName within the ... More on community.n8n.io
🌐 community.n8n.io
1
0
December 2, 2022
Accessing nested objects like 2D arrays
So I’m not sure whether I have a fundamental misunderstanding of how objects work, but I’m trying to write a program which requires accessing nested objects, however it’s not a simple case of accessing the object via the object name. For example, if I have: const itemsList = { item1: ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
April 22, 2022
How to access nested properties of an object using variable?
JavaScript doesn't have a built-in way to parse variable paths like this, but there are libraries that can, such as lodash which has a set function for doing this. You can also make your own which isn't too hard if you only want something simple. For example, this version of set splits a path by the dot operator and sets the value in the specified object. function set(object, path, value) { const keys = path.split(".") const valueKey = keys.pop() const target = keys.reduce((target, key) => target[key], object) return target[valueKey] = value } You could then replace filter[target] = value with set(filter, target, value) This doesn't do anything fancy like the lodash version such as recognize bracket syntax ([]) or create objects if they don't already exist, but it should more or less work for what you need. More on reddit.com
🌐 r/learnjavascript
3
1
November 7, 2023
How to access nested objects with the same key name in json?
const myObj = { data: { data: { number: 1, letter: "a" } } }; function getSecond(obj, propName) { return obj[propName][propName]; } const second = getSecond(myObj, "data"); console.log(second); // {number: 1, letter: "a"} second.number++; console.log(second); // {number: 2, letter: "a"} More on reddit.com
🌐 r/learnjavascript
6
2
July 10, 2020
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Accessing Nested Objects - JavaScript - The freeCodeCamp Forum
July 15, 2017 - So for the Javascript challenges, I am stuck in the “Accessing Nested Objects” part. The sub-properties of objects can be accessed by chaining together the dot or bracket notation.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-access-and-process-nested-objects-arrays-or-json
How to Access and Process Nested Objects, Arrays, or JSON? - GeeksforGeeks
Optional chaining (?.) is used for safely accessing deeply nested properties without causing errors if any part of the path is undefined or null. This helps in preventing runtime errors in complex data structures. ... const o1 = { o2: { name: "Sourav" // 'contact' may not always exist } }; // No error even if 'contact' is undefined console.log(o1.o2?.contact?.email); ... The for...in loops are used for iterating through the properties of objects, while for...of loops are used for arrays.
Published   July 23, 2025
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › object › get nested object property
Get a nested object property by key or path in JavaScript - 30 seconds of code
March 22, 2024 - The simplest scenario and by far the most common is having an array of keys that represent the path to the desired property in the object. In that case, all you need to do is use Array.prototype.reduce() to iterate over the keys and get the ...
🌐
Vishal Kukreja
vishalkukreja.com › home › blog › how to access nested arrays and objects in javascript
How to Access Nested Arrays and Objects in JavaScript - Vishal Kukreja
January 20, 2025 - If the value of a key is an object, we use a nested for…in loop to iterate through its key-value pairs. Like accessing nested Arrays and Objects, there is an article for updation. Checkout article with e.g. here JavaScript : Find and update a value in an array of objects.
🌐
Medium
medium.com › geekculture › accessing-data-inside-nested-data-structures-in-javascript-an-example-21c5ea1372e3
Accessing Data Inside Nested Data Structures in JavaScript — An Example | by Abby Anderson | Geek Culture | Medium
October 18, 2021 - When I was first introduced to nested data structures in JavaScript, I had a hard time understanding how to extract data from the innermost layers. I’ll walk you through an example here, which I hope will help some other JavaScript learners out there. Explaining JavaScript objects and arrays ...
Find elsewhere
🌐
HNG Learn
hng.tech › hng learn › learn javascript programming online › accessing nested objects
Accessing Nested Objects | Learn JavaScript Programming online | HNG Learn
1 month ago - This means that an object can contain properties that are also objects themselves. Accessing Nested Objects: To access values within nested objects, you need to use dot notation or bracket notation.
🌐
HackerNoon
hackernoon.com › accessing-nested-objects-in-javascript-f02f1bd6387f
Accessing Nested Objects in JavaScript
February 21, 2018 - #programming#software-development#javascript#web-development#coding#software-engineering#python#react#open-source#nodejs#tutorial#mobile-app-development#api#java#software-architecture#docker#kubernetes#development#github#serverless#front-end-development#android#testing#web-design#typescript#reactjs#learning-to-code#css#linux#software-testing#golang#software#debugging#ios#user-experience#frontend#html#backend#react-native#webdev#algorithms#app-development#javascript-development#engineering#learn-to-code#git#mobile-apps#android-app-development#functional-programming#php#code-quality#sql#developer#developer-tools#angular#apps#clean-code#ios-app-development#programming-languages#dotnet#mobile#ruby#performance#containers#ruby-on-rails#swift#rest-api#go#coding-skills#python-tutorials#solidity#monitoring#graphql#ui#website-development
🌐
Better Programming
betterprogramming.pub › 4-ways-to-safely-access-nested-objects-in-vanilla-javascript-8671d09348a8
4 Ways to Safely Access Nested Objects in Vanilla Javascript | by Zeng Hou Lim | Better Programming
September 10, 2019 - 4 Ways to Safely Access Nested Objects in Vanilla Javascript How to access nested objects and write safer code If you’re working with Javascript, chances are you might have encountered a situation …
🌐
Medium
medium.com › @mcdonough.mollya › working-with-nested-objects-in-javascript-aad41ae5ed85
Working with Nested Objects in JavaScript | by Molly McDonough | Medium
March 4, 2022 - Properties can also be accessed by dot notation if you know the literal string. Bracket notation must be used for any keys with characters not accepted by dot notation (such as my spaces in the above example), or if you are passing the value of a variable rather than the literal string. Now that I’ve covered the basic syntax of JavaScript objects I want to talk about nested ...
🌐
Medium
medium.com › geekculture › this-is-how-to-access-nested-objects-dynamically-in-javascript-a26c7cf52461
This is How to Access Nested Objects Dynamically in JavaScript | by Lanka Rathnayaka | Geek Culture | Medium
February 11, 2023 - Array with all the objects that need to be filtered [{…},{…}] String value that should be searched “Harison” · Keys of the object as a string array in form with dot notation. where we should look at the object.
🌐
TutorialsPoint
tutorialspoint.com › how-to-access-nested-json-objects-in-javascript
How to access nested json objects in JavaScript?
In the following example 'vehicles' is a object which is inside a main object called 'person'. Using dot notation the nested objects' property(car) is accessed.
🌐
W3Schools
w3schools.com › js › tryit.asp
Access Nested JavaScript Objects
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
EyeHunts
tutorial.eyehunts.com › home › how to access a nested array of objects in javascript | example code
How to access a nested array of objects in JavaScript | Code
September 22, 2022 - `items` object contain array of two objects as elements*/ console.log(data.items); /* 3. you need 2nd element of array - the `1` from `[0, 1]`*/ console.log(data.items[1]); /* 4. and you need value of `name` property of 2nd object-element of array)*/ console.log(data.items[1].name); Do comment if you have any doubts or suggestions on this JS nested array topic. Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser. ... You must be logged in to post a comment. ... Subscribe now to keep reading and get access to the full archive.
🌐
xjavascript
xjavascript.com › blog › accessing-nested-javascript-objects-and-arrays-by-string-path
How to Access Nested JavaScript Objects and Arrays by String Path: A Complete Guide with Examples — xjavascript.com
Often, you may need to access deeply nested values using a **dynamic string path** (e.g., `'user.addresses[0].street'` instead of hardcoding `user.addresses[0].street`). This guide will walk you through multiple methods to achieve this, from ...
🌐
Delft Stack
delftstack.com › home › howto › javascript › nested objects javascript
Nested Objects in JavaScript
February 2, 2024 - You can create nested objects within a nested object. In the following example, Salary is an object that resides inside the main object named Employee. The dot notation can access the property of nested objects.
🌐
DEV Community
dev.to › iamcymentho › demystifying-nested-data-a-guide-to-accessing-and-processing-objects-arrays-and-json-in-javascript-34im
Demystifying Nested Data: A Guide to Accessing and Processing Objects, Arrays, and JSON in JavaScript - DEV Community
September 15, 2023 - In JavaScript, you can parse JSONdata from a string into a JavaScript object using the JSON.parse() method: ... This section provides real-world scenarios and code examples demonstrating how to work with nested data.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Accessing nested objects like 2D arrays - JavaScript - The freeCodeCamp Forum
April 22, 2022 - So I’m not sure whether I have a fundamental misunderstanding of how objects work, but I’m trying to write a program which requires accessing nested objects, however it’s not a simple case of accessing the object via the object name. For example, if I have: const itemsList = { item1: { ID: 0, itemName: "Item one", ... }, item2: { ID: 1, itemName: "Item two", ... }, ... } In my code, I want to access a particular item using a number which corresponds to the ID ...