{"id":16007,"date":"2022-12-31T10:40:52","date_gmt":"2022-12-31T05:10:52","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=16007"},"modified":"2025-10-21T14:33:16","modified_gmt":"2025-10-21T09:03:16","slug":"how-to-render-an-array-of-objects-in-react","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/how-to-render-an-array-of-objects-in-react\/","title":{"rendered":"How to Render an Array of Objects in React? [in 3 easy steps]"},"content":{"rendered":"\n<p>Do you have an array of objects or data items and want to list them in your React app? Well, you&#8217;re at the right place! Rendering an array of objects is pretty simple and this blog has been written to make it even more simpler for you. <\/p>\n\n\n\n<p>In this blog, we\u2019ll learn <strong><em>how to render an array of objects or data items in a react component with JSX and work on react map array of objects, keys in react, and how you can filter out data items with the help of JavaScript methods. <\/em><\/strong><\/p>\n\n\n\n<p>Rendering arrays of objects in React can be a challenge for developers who are new to the framework. Fortunately, React provides a powerful yet simple way of rendering data in an efficient manner. Let&#8217;s discuss this at length:<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is an Array of Objects<\/strong>?<\/h2>\n\n\n\n<p>An array of objects simply called a &#8216;List&#8217; in React, is the collection of data having similar information. An array of objects can be anything like different data structures, car names, etc. <\/p>\n\n\n\n<p>The most popular way to create a list or render an array of objects in <a href=\"https:\/\/legacy.reactjs.org\/docs\/getting-started.html\" target=\"_blank\" rel=\"noopener\">React<\/a> is using the <strong>array.map() <\/strong>method which takes an array of data and maps it to an array of components, so that each data item is represented by a corresponding component. <\/p>\n\n\n\n<p>If you would like to explore React through a self-paced course, try HCL <a href=\"https:\/\/www.guvi.in\/courses\/web-development\/react-js\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=How+to+Render+an+Array+of+Objects+in+React\">GUVI\u2019s React Self-paced certification course<\/a>.<\/p>\n\n\n\n<p>Additionally, the map() function can help with debugging and performance. This was just to give you a gist of what we&#8217;re about to discuss. Let&#8217;s dive into the details now!<\/p>\n\n\n\n<p>With the help of available <a href=\"https:\/\/www.guvi.in\/hub\/javascript\/what-is-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScri<\/a>pt Array.map() and filter() methods, the array of objects\/items can be transformed into an array of components, also known as a list. <\/p>\n\n\n\n<p>Lists are commonly used to store data retrieved from a server, like any user information, etc. Each data object\/item in the array consists of properties that can be easily accessed and manipulated. <\/p>\n\n\n\n<p>For example, an array of objects in React could contain a list of car names, each of which has its own model and name. See the below syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const carData = &#91;\n  {\n\tname: \u2018BMW\u2019,\n\tmodel: 2022\n  },\n {\n\tname: Audi,\n\tmodel: 2021\n  },\n]\n<\/code><\/pre>\n\n\n\n<p>Given above is a list or <a href=\"https:\/\/www.guvi.in\/blog\/guide-for-arrays-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a> of objects consisting of names, and models of cars each of those having different properties. <\/p>\n\n\n\n<p>We can use these arrays of objects to pass information between different components, store data in a state, or even populate lists in a component.<\/p>\n\n\n\n<p>To render an array of objects\/items in React, we have different ways such as: iterating a loop and using the map() and filter() functions. Out of all these methods, the most popular way is using <em><strong>Array.map()<\/strong>.<\/em><\/p>\n\n\n\n<p><strong>Also Read: <a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-props-in-react\/\">How to use Props in React.<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Rendering an array of objects using JavaScript map()<\/strong><\/h2>\n\n\n\n<p>To render an array of objects\/items in React, we loop through the array using the <em><strong>.map()<\/strong><\/em><strong> <\/strong>method and return a single item. <\/p>\n\n\n\n<p>In the below example, we loop through the <em><strong>courses<\/strong><\/em> array and return a <strong>&lt;li&gt;<\/strong> element for each item. We can use this method when we want to display a single element for each item in the given array.&nbsp;<\/p>\n\n\n\n<p>When we call the <em>.map() <\/em>function in JavaScript, it converts the array into whatever we return from the callback function we pass into it. This function always creates a new array. Let\u2019s understand one <strong>example<\/strong> in detail, step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Steps to render an array of objects\/list:<\/strong><\/h2>\n\n\n\n<p>Below are the steps needed to render an array of objects or lists in React:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Create a react application<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>npx create-react-app demo<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Changing the directory<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>cd demo<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Creating data as an array<\/strong><\/h3>\n\n\n\n<p>Once we have created a new <a href=\"https:\/\/www.guvi.in\/blog\/steps-to-create-stopwatch-using-reactjs\/\" target=\"_blank\" rel=\"noreferrer noopener\">React application<\/a>, add the following code in the App.js file before the functional component App().<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const courses = &#91;\n&nbsp;&nbsp;\"Full Stack Developement Program\",\n&nbsp;&nbsp;\"Python Automation Testing Program\",\n&nbsp;&nbsp;\"UI\/UX Program\",\n];<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Mapping the array into a new array of JSX nodes as <\/strong><strong>arrayDataItems<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const arrayDataItems = courses.map((course) =&gt; &lt;li&gt;{course}&lt;\/li&gt;);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5: Return <\/strong><strong>arrayDataItems <\/strong><strong>from the component wrapped in &lt;ul&gt;<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Complete Example:<\/strong><\/h3>\n\n\n\n<p><strong><em>App.js file<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import \".\/App.css\";\n\nimport React from \"react\";\n\n\/\/define the mock data\n\nconst courses = &#91;\n&nbsp;&nbsp;\"Full Stack Developement Program\",\n&nbsp;&nbsp;\"Python Automation Testing Program\",\n&nbsp;&nbsp;\"UI\/UX Program\",\n];\n\nfunction App(props) {\n\n&nbsp;&nbsp;\/* Mapping the courses into a new array of JSX nodes as arrayDataItems *\/\n&nbsp;&nbsp;const arrayDataItems = courses.map((course) =&gt; &lt;li&gt;{course}&lt;\/li&gt;);\n\n&nbsp;&nbsp;return (\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"container\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Render List\/Array of Items&lt;\/h1&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* returning arrayDataItems wrapped in &lt;ul&gt; *\/}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;);\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"491\" height=\"304\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385013415.png\" alt=\"\" class=\"wp-image-16010\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385013415.png 491w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385013415-300x186.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385013415-150x93.png 150w\" sizes=\"(max-width: 491px) 100vw, 491px\" title=\"\"><figcaption class=\"wp-element-caption\">Render array of items\/objects<\/figcaption><\/figure><\/div>\n\n\n<p>One thing that you may notice here is that the console will give you a warning such as the one below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Warning: Each child in a list should have a unique \u201ckey\u201d prop.<\/pre>\n\n\n\n<p>This warning states that we need to provide a unique key to each data item in the array. Next, we will examine why we want to add a unique key to a list of elements rendered by an array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Keys in React<\/strong><\/h2>\n\n\n\n<p>Keys in React help in knowing which array data item each component corresponds to. Also, Keys in React help in identifying and updating each item between renders without causing any bugs. <\/p>\n\n\n\n<p>Rendering an array of items into a React component makes it important to always provide a key to track the items between renders. Generally, we use id: as the key in various data arrays.<\/p>\n\n\n\n<p>Keys has some rules that we must follow to avoid any errors:<\/p>\n\n\n\n<ul>\n<li><strong>Keys must be unique<\/strong>&#8211; every item of the array must have a unique key.<\/li>\n\n\n\n<li><strong>Keys must be permanent<\/strong>&#8211; keys should not change their purpose or must not be changed between re-renders.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h2>\n\n\n\n<p>Let\u2019s understand how we use keys in React to render an array of objects\/lists. We must use keys in our data. For demonstrating this example, step1 and step2 will be the same.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Creating data as an Array with Key<\/strong><\/h3>\n\n\n\n<p>Once we have created a new React application, add the following code to the App.js file before the functional component App(). <\/p>\n\n\n\n<p>Earlier, we hadn\u2019t specified the unique key in the data, but now we have used it in our structured data to avoid warnings\/errors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const courses = &#91;\n\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 0,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Full Stack Developement Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999'\n\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 1,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Python Automation Testing Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '64,999'\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 2,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'UI\/UX Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999'\n&nbsp;&nbsp;}\n]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Mapping the array into a new array of JSX nodes as <\/strong><strong>arrayDataItems<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const arrayDataItems = courses.map(course =&gt;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;li key={course.id}&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;{course.name}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span&gt;{course.price}&lt;\/span&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;\n\n&nbsp;&nbsp;)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Return the <\/strong>array of <strong>Data Items from the component wrapped in &lt;ul&gt;<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Complete Example:<\/strong><\/h3>\n\n\n\n<p><strong><em>App.js file<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import \".\/App.css\";\nimport React from \"react\";\n\n\/\/define the mock data with keys\nconst courses = &#91;\n\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 0,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Full Stack Developement Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999'\n&nbsp;&nbsp;},\n\n&nbsp;&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;id: 1,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Python Automation Testing Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '64,999'\n&nbsp;&nbsp;},\n\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 2,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'UI\/UX Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999'\n&nbsp;&nbsp;}\n\n]\n\nfunction App() {\n\n&nbsp;&nbsp;\/* Mapping the courses into a new array of JSX nodes as arrayDataItems *\/\n\n&nbsp;&nbsp;const arrayDataItems = courses.map(course =&gt;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;li key={course.id}&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;{course.name}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span&gt;{course.price}&lt;\/span&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;\n&nbsp;&nbsp;)\n\n&nbsp;&nbsp;return (\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"container\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Render List\/Array of Items with Key&lt;\/h1&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* returning arrayDataItems wrapped in &lt;ul&gt; *\/}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;);\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<p><strong><em>App.css file<\/em><\/strong><em> <\/em>(Optional)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.container {\n&nbsp;&nbsp;margin-left: 20px;\n}\n\n.container h1 {\n&nbsp;&nbsp;color: green\n}\n\n.container li {\n&nbsp;&nbsp;display: flex;\n&nbsp;&nbsp;flex-direction: column;\n&nbsp;&nbsp;font-size: 20px;\n&nbsp;&nbsp;background-color: #35F543;\n&nbsp;&nbsp;width: 400px;\n&nbsp;&nbsp;color: white;\n&nbsp;&nbsp;padding: 2px;\n&nbsp;&nbsp;border-radius: 20px;\n&nbsp;&nbsp;justify-content: center;\n&nbsp;&nbsp;align-items: center;\n&nbsp;&nbsp;margin-bottom: 10px;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"743\" height=\"610\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385019204.png\" alt=\"\" class=\"wp-image-16012\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385019204.png 743w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385019204-300x246.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385019204-150x123.png 150w\" sizes=\"(max-width: 743px) 100vw, 743px\" title=\"\"><figcaption class=\"wp-element-caption\">Keys in React<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>Filtering arrays of items<\/strong><\/h2>\n\n\n\n<p>Till now we are returning a full array of items but what if we only want to show courses with a specific category? Then, we can use <strong>JavaScript&#8217;s filter() method <\/strong>to return just those with a matching category. <\/p>\n\n\n\n<p>Filter() method takes an array of objects\/items, passes and checks whether the function returns true or false, and finally returns a new array of filtered items that returned true. Let\u2019s understand with the help of an example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const courses = &#91;\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 0,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Full Stack Developement Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: Software Development\u2019\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 1,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Python Automation Testing Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '64,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: Testing\u2019\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n&nbsp;&nbsp; &nbsp;id: 2,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'UI\/UX Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: design\u2019\n&nbsp;&nbsp;}\n]<\/code><\/pre>\n\n\n\n<p>In the above data, we have three different categories and let\u2019s say we want only courses related to \u201cTesting\u201d, then the filter() method will return the course having a category as \u201cTesting\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Create a new array having the category \u201cTesting\u201d&nbsp;<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const testings = courses.filter(course&nbsp; =&gt;\n&nbsp;&nbsp;course.category === 'Testing\u2019\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Mapping over \u201cTesting\u201d&nbsp;<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const arrayDataItems = testings.map(course =&gt;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;li key={course.id}&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;{course.name}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span&gt;{course.price}&lt;\/span&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;{course.category}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;\n&nbsp;&nbsp;)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Return <\/strong><strong>arrayDataItems <\/strong><strong>from the component wrapped in &lt;ul&gt;<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Complete Example:<\/strong><\/h3>\n\n\n\n<p><strong><em>App.js file<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import \".\/App.css\";\nimport React from \"react\";\n\n\/\/define the mock data with keys\nconst courses = &#91;\n\n&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;id: 0,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Full Stack Developement Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: 'Software Developmen',\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;id: 1,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'Python Automation Testing Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '64,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: 'Testing',\n&nbsp;&nbsp;},\n&nbsp;&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;id: 2,\n&nbsp;&nbsp;&nbsp;&nbsp;name: 'UI\/UX Program',\n&nbsp;&nbsp;&nbsp;&nbsp;price: '89,999',\n&nbsp;&nbsp;&nbsp;&nbsp;category: 'design'\n&nbsp;&nbsp;}\n]\n\nfunction App() {\n\n&nbsp;&nbsp;\/* new array of only 'testing' category *\/\n&nbsp;&nbsp;const testings = courses.filter(course&nbsp; =&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;course.category === 'Testing'\n&nbsp;&nbsp;);\n\n&nbsp;&nbsp;\/* Mapping the courses into a new array of JSX nodes as arrayDataItems *\/\n&nbsp;&nbsp;const arrayDataItems = testings.map(course =&gt;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;li key={course.id}&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;{course.name}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span&gt;{course.price}&lt;\/span&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p id=\"category\"&gt;{course.category}&lt;\/p&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;\n\n&nbsp;&nbsp;)\n\n&nbsp;&nbsp;return (\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"container\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Filtering List\/Array of Items&lt;\/h1&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\/* returning arrayDataItems wrapped in &lt;ul&gt; *\/}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;{arrayDataItems}&lt;\/ul&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;);\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<p><strong>Wondering how you can code like this with ease? We&#8217;ve got the perfect learning resource: HCL <a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/\">GUVI&#8217;s highly accredited Full Stack Development Bootcamp<\/a> will turn you into a coding and development ninja in no time! Follow the link to learn more.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"557\" height=\"389\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385024774.png\" alt=\"\" class=\"wp-image-16011\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385024774.png 557w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385024774-300x210.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/screely-1672385024774-150x105.png 150w\" sizes=\"(max-width: 557px) 100vw, 557px\" title=\"\"><figcaption class=\"wp-element-caption\">Filtering arrays in React<\/figcaption><\/figure><\/div>\n\n\n<p><em>If you&#8217;re a React learner, must read the<a href=\"https:\/\/www.guvi.in\/blog\/prerequisites-for-reactjs\/\"> <strong>6 Essential Prerequisites For Learning ReactJS<\/strong><\/a>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concluding Thoughts&#8230;<\/h2>\n\n\n\n<p>I hope this blog has helped you gain a much better understanding of rendering a list or array of objects in React. To render an array of objects, we saw <strong>how to use an array.map() function<\/strong> (and use React map array of objects). <\/p>\n\n\n\n<p>Apart from this, we learned <strong>how to create an array of filtered items using JavaScript\u2019s filter() method. <\/strong>We also noticed that whilst rendering an element inside the component, we must use a unique key to avoid any errors. <\/p>\n\n\n\n<p>Regardless of which method we use, it is important to remember that we need to access the data within the object to render it correctly.<\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1683863921977\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do you render multiple objects in React?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can\u00a0<strong>use the Array&#8217;s map functionality<\/strong> to render multiple elements in React. Simply map all your objects into React fragments, so that your Function component can make use of it. But don&#8217;t forget to set a unique key prop!<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1683863986735\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I render multiple components?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Even if we have multiple elements to render, there can only be a single root element. This means that if we want to render two or more elements, we have to\u00a0<strong>wrap them in another element or component<\/strong>. Commonly, the element used for this is a &lt;div> tag.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1683864224284\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How to render an array of objects in React?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Using these simple and easy steps, you can render an array of objects in React:<\/p>\n<p><em><strong>Step 1: <\/strong>Create a react application. <br \/><strong>Step 2: <\/strong>Change directory. <br \/><strong>Step 3: <\/strong>Create<\/em> data as an <em>array. <br \/><strong>Step 4: <\/strong>Mapping the array into a new array of JSX nodes as arrayDataItems. <br \/><strong>Step 5:<\/strong> Return arrayDataItems from the component wrapped in &lt;ul><\/em><\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1693296319774\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do you iterate an array of objects in React JS?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To iterate through an array of objects in ReactJS, you must use the mao() method. It creates a new array by applying a provided function to each element of the original array. Within the function, you can access and render each object&#8217;s properties as and when needed, effectively iterating through and rendering them in your React component.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1693296494404\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do you set an array of objects in state in React JS?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To set an array of objects in the state of a React component, you can use the &#8216;useState&#8217; hook. So to do this, first, import &#8216;useState&#8217; from &#8216;react&#8217;. Then, declare a state variable using useState and initialize it with your array of objects. To update the state, use the setter function provided by the useState hook. And voila, now you can easily manage and modify the array of objects within your component&#8217;s state.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Do you have an array of objects or data items and want to list them in your React app? Well, you&#8217;re at the right place! Rendering an array of objects is pretty simple and this blog has been written to make it even more simpler for you. In this blog, we\u2019ll learn how to render [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":71884,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[814,816,815],"views":"165301","authorinfo":{"name":"GUVI Geek","url":"https:\/\/www.guvi.in\/blog\/author\/admin\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/How-to-Render-an-Array\u2028Of-Objects-in-React_-\u2028in-3-easy-steps-300x116.webp","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2022\/12\/How-to-Render-an-Array\u2028Of-Objects-in-React_-\u2028in-3-easy-steps.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16007"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=16007"}],"version-history":[{"count":31,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16007\/revisions"}],"predecessor-version":[{"id":90024,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16007\/revisions\/90024"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/71884"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=16007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=16007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=16007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}