DEV Community

Discussion on: Why is using javascript “for loop” for array iteration a bad idea?

Collapse
_prosen profile image
Prosen Ghosh Author

I use loop or array methods depending on what/which purpose i'm using it for.

In the below code example for loop or forEach() will not going to serve my purpose in a easy to readable/understandable way.

function ListItems({ items }) {
  const listItems = items.map((item) =>
    <li>{item}</li>
  );
  return (
    <ul>{listItems}</ul>
  );
}
Enter fullscreen mode Exit fullscreen mode