Loop

Loop through an array

const comments = [
    { id: 1, text: 'Comment 1' },
    { id: 2, text: 'Comment 2' },
    { id: 3, text: 'Comment 3' },
];
<ul>
  {comments.map((comment, index) => (
    <li key={index}>{comment.text}</li>
  ))}
</ul>
Was this page helpful?