How to display keys and values of objects in a loop in React?

Loop through object keys and values using Object.entries() and map() to render data dynamically in React.

intermediateConditional renderingreactobjectmaploops
Published: 10/26/2025
Updated: 10/26/2025

Question

How to display keys and values of objects in a loop in React?


Answer

You can’t map directly over an object — first, convert it into an array using Object.entries().

function UserDetails() {
  const user = { name: 'Ghazi', role: 'Engineer', country: 'India' };

  return (
    <ul>
      {Object.entries(user).map(([key, value]) => (
        <li key={key}>
          <strong>{key}:</strong> {value}
        </li>
      ))}
    </ul>
  );
}

✅ Other useful methods:

  • Object.keys(obj) → returns an array of keys
  • Object.values(obj) → returns an array of values

Real-World Example

Rendering user profiles, config summaries, or any object-based data structure.

Quick Practice

Create a component that displays all properties of a product object (name, price, stock) using Object.entries().

Summary

Use Object.entries() + map() to render object keys and values cleanly in React.

Frequently Asked Questions

Can I loop objects directly in JSX?

Not directly. Convert them to arrays first using Object.keys, Object.values, or Object.entries.


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.