I am trying to fetch the dev or stage key from the array inside the map function based on a declared variable called "abc". instead of {data.dev}, i want to make it like {data.abc} some thing like that This might be easy but since i am new, not able to figure out
const data = [
{ id: 1, name: "John Doe", dev: "new", stage: "new" },
{ id: 2, name: "Victor Wayne", dev: "old", stage: "old" },
{ id: 3, name: "Jane Doe", dev: "freq", stage: "old" },
];
const abc='dev';
return (
<div className="users">
{data.map((data) => (
<div className="user">{data.abc}</div>
))}
</div>
);
};
mapfunction. You said you wanted to usedata.nameinstead ofdata.dev, which you can certainly do. What are you trying to output?data[abc].) or square bracket notation ([]) to access properties of something (e.g.person.nameorperson[0]). While[]is most commonly used for array indices, you could use it for object keys. This MDN doc entry and this blog article might be useful for you.