How can I handle single value which comes as obj in map method in React class component?
JSON values below:
{
"name": "john",
"age": 30
}
React component below:
{this.props.test && this.props.test.map((val, key) => {
return (
<>
{val._attributes.type === "25" &&
(
<TestComponent/>
)}
}
props.test? Is this the object you showed? If so -mapwouldn't work for it, it is a method of arrays. If it is an array of these objects, themapfunction receives the element in the array as first argument, and its index as second, not the key and value (which is an objects concept) - raz-ezra