MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Rendering Lists with the Array map Method0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
6.1Rendering Lists with the Array map Method6.2The Critical Importance of Unique Keys6.3Avoiding Array Indices as Keys6.4Filtering and Sorting List Data Dynamically
HomeTutorialsReact.js for BeginnersRendering Lists with the Array map Method
The Critical Importance of Unique Keys

Rendering Lists with the Array map Method

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Transforming Data Collections into UI

Modern web applications are built around collections of data: lists of products, feeds of social posts, tables of transactions, or directories of courses. In React, you don't write manual for loops to insert DOM elements. Instead, you use JavaScript's functional Array.prototype.map() method to transform an array of data objects into an array of JSX elements.

1Data Array:
2['HTML5', 'CSS3', 'JavaScript']
3 │
4 ▼ .map(item => <li>{item}</li>)
5JSX Array:
6[<li>HTML5</li>, <li>CSS3</li>, <li>JavaScript</li>]
7 │
8 ▼ React renders to DOM:
9<ul>
10 <li>HTML5</li>
11 <li>CSS3</li>
12 <li>JavaScript</li>
13</ul>

2. Basic List Rendering

Here is a straightforward example rendering an array of strings:

1import React from 'react';
2 
3export default function TechStack() {
4 const technologies = ['React', 'TypeScript', 'Tailwind CSS', 'Vite'];
5 
6 return (
7 <div className="tech-container">
8 <h3>Course Tech Stack</h3>
9 <ul>
10 {technologies.map((tech) => (
11 <li key={tech} className="tech-item">
12 {tech}
13 </li>
14 ))}
15 </ul>
16 </div>
17 );
18}

3. Rendering Arrays of Objects

In enterprise applications, data almost always arrives from APIs as an array of objects. You can map over these objects and extract their properties cleanly:

1import React from 'react';
2 
3const COURSES = [
4 { id: 'c-101', title: 'React for Beginners', level: 'Beginner', duration: '12h' },
5 { id: 'c-102', title: 'Full-Stack Node.js', level: 'Intermediate', duration: '18h' },
6 { id: 'c-103', title: 'Django Enterprise API', level: 'Advanced', duration: '24h' }
7];
8 
9export default function CourseDirectory() {
10 return (
11 <div className="course-grid">
12 {COURSES.map((course) => (
13 <div key={course.id} className="course-card">
14 <h4>{course.title}</h4>
15 <p>Level: <span className="badge">{course.level}</span></p>
16 <span className="duration">⏱ {course.duration}</span>
17 </div>
18 ))}
19 </div>
20 );
21}

4. Clean Code: Extracting Child Components

When each list item contains complex markup, multiple event handlers, or local state, inline JSX inside .map() can become difficult to read and maintain.

The industry standard pattern is to extract the item into its own dedicated component:

1// Dedicated child item component
2function CourseCard({ course, onEnroll }) {
3 return (
4 <div className="course-card">
5 <h4>{course.title}</h4>
6 <p>Level: {course.level}</p>
7 <button onClick={() => onEnroll(course.id)}>Enroll Now</button>
8 </div>
9 );
10}
11 
12// Parent list component
13export default function CourseList({ courses, onEnrollCourse }) {
14 return (
15 <div className="course-list">
16 {courses.map((course) => (
17 <CourseCard
18 key={course.id}
19 course={course}
20 onEnroll={onEnrollCourse}
21 />
22 ))}
23 </div>
24 );
25}

Note: The key prop must always be placed directly on the element or component returned inside the .map() callback (here, on <CourseCard key={course.id} />), not inside the child component.


Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which JavaScript array method is the primary tool for rendering lists of elements in React?
Question 2
Why is forEach() NOT used directly inside JSX curly braces to render a list?
Question 3
Where must the key prop be placed when mapping an array to a custom child component?
Question 4
What happens if you pass an empty array [] to .map() in React JSX?
Question 5
What is the primary readability benefit of extracting list items into a separate sub-component?
Next Lesson

The Critical Importance of Unique Keys

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Preventing Default Browser BehaviorsThe Critical Importance of Unique Keys

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext