CARVIEW |
Select Language
HTTP/2 200
content-type: text/html; charset=utf-8
date: Tue, 19 Aug 2025 05:26:05 GMT
permissions-policy: interest-cohort=()
strict-transport-security: max-age=31536000; includeSubDomains
server: nginx
cache-control: s-maxage=44225, max-age=0
x-powered-by: Next.js
etag: "d1n174gt7g3klz"
content-encoding: gzip
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'self' http: https: ws: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; frame-ancestors 'self';
vary: Accept-Encoding
x-cache: Miss from cloudfront
via: 1.1 d03e1fdb296cec133b80d2f6e5d8974a.cloudfront.net (CloudFront)
x-amz-cf-pop: BOM78-P9
x-amz-cf-id: O_UAA7An_qpbLf4xxhn1hP943G4b_MYcadz5QrJffuJRk7Q8FJZJNg==
React | Lists and Keys | Question 6
JavaScript
Interview Preparation
- Interview Preparation For Software Developers
- Must Coding Questions - Company-wise
- Must Do Coding Questions - Topic-wise
- Company-wise Practice Problems
- Company Preparation
- Competitive Programming
- Software Design-Patterns
- Company-wise Interview Experience
- Experienced - Interview Experiences
- Internship - Interview Experiences
React | Lists and Keys | Question 6
Last Updated :
Discuss
Comments
What is the issue with this code in terms of key assignment?
const list = ["apple", "banana", "cherry"];
return (
<ul>
{list.map((fruit, index) => (
<li key={index}>{fruit}</li>
))}
</ul>
);
Using index as a key is fine in all cases
index should not be used as a key when the list can change dynamically
The key should always be a string
key should be assigned to the ul tag
This question is part of this quiz :
Lists and Keys in ReactShare your thoughts in the comments

GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy