Suppose you have an array of objects that you want to render in your React application in JSX. Let’s call the array of objects data
. We then proceed to output the object’s key and value pairs in an unorder list in the following manner using map
:
return (
<div>
<h1>Key/Value Pairs</h1>
{Object.keys(data).map(key, i) =>(
<ul>
<li>{key}: {data[key]}</li>
</ul>
)}
</div>
)