---
title: "ReactJS | Lists and Keys Tutorial with Example"
url: "https://magecomp.com/blog/reactjs-lists-and-keys/"
date: "2023-02-08T15:58:42+00:00"
modified: "2025-02-27T09:07:14+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "ReactJS"
word_count: 318
reading_time: "2 min read"
summary: "Hello ReactJS Friends,"
description: "Keys give an identity to the elements. Learn more about Lists and Keys in ReactJS with examples."
keywords: "ReactJS"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Implement Multi-Language in React?"
    url: "https://magecomp.com/blog/implement-multi-language-react/"
  - title: "Lazy Loading in ReactJS with Example"
    url: "https://magecomp.com/blog/lazy-loading-reactjs/"
  - title: "How to Implement Redux in ReactJS?"
    url: "https://magecomp.com/blog/redux-in-reactjs/"
---

# ReactJS | Lists and Keys Tutorial with Example

_Published: February 8, 2023_  
_Author: Bharat Desai_  

![ReactJS Lists and Keys Tutorial with Example](https://magecomp.com/blog/wp-content/uploads/2023/02/ReactJS-Lists-and-Keys-Tutorial-with-Example-1024x512.webp)

**Hello ReactJS Friends,**

Lists and Keys in React are the most common concepts used for almost every ReactJS Application. Let’s learn about lists and Keys in ReactJS with examples.
[![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-1.webp)](https://magecomp.com/hire-reactjs-developer.html)

## Lists and Keys in ReactJS
A “key” is a special string attribute. Keys must be included when creating lists of elements in React.
## Uses of Keys in ReactJS
- Keys are used in React to identify which items have been changed, updated, or deleted from the list.- It also helps to determine which components need to be rerendered instead of rerendering the whole set of components.- Keys are used to give an identity to the elements in the lists.
The next thing that comes to mind is what should be good to be chosen as the key for the items in the lists. Using a string as a key that uniquely identifies the items in the list is recommended.
## Example:
The below example shows a list with string keys.
```
const numbers = [ 1, 2, 3, 4, 5 ];

const updatedNums = numbers.map((number)=>{
return {number} ;
})
```

We can also assign the array indexes as keys to the list items.
```
const numbers = [ 1, 2, 3, 4, 5 ];

const updatedNums = numbers.map((number, index)=>
{number}
);
```

**Output:**

[![SS 1](https://magecomp.com/blog/wp-content/uploads/2023/02/SS-1.png)](https://magecomp.com/blog/wp-content/uploads/2023/02/SS-1.png)

When we set the key in any tag with the ‘key’ keyword, the error of the key prop is gone.
```
function App()
{
    const menuItems = [1, 2, 3, 4, 5];
    return (
                        {
            menuItems.map(el => {
                return {el}            })
        }
                    );
}
```

[![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-2.webp)](https://magecomp.com/services/contact-us/)

**Output:**

[![lists and keys](https://magecomp.com/blog/wp-content/uploads/2023/02/SS-2.png)](https://magecomp.com/blog/wp-content/uploads/2023/02/SS-2.png)

## Conclusion:
This was all about Lists and Keys in ReactJS. Hope the examples mentioned above will help you better understand Lists and Keys in React. [**Hire ReactJS Developers**](https://magecomp.com/hire-reactjs-developer.html) for all your development needs.
Share the tutorial with your other RectJS friends, and stay in touch with us for more tutorials on ReactJS.
[![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-3.webp)](https://magecomp.com/hire-reactjs-developer.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/reactjs-lists-and-keys/](https://magecomp.com/blog/reactjs-lists-and-keys/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-05-14 17:39:14 UTC_  
