I think the reason you have a problem with iterating over results is because it's not in a good shape:
try this if you can:
import React from "react";
const Salary = () => {
const results = [
{
ID: "shops",
Name: "Shopping",
subs: [
{ ID: "food.order", Name: "Food" },
{ ID: "drink.order", Name: "Drink" }
]
},
{
ID: "fun",
Name: "Sports",
subs: [
{ ID: "play.basketball", Name: "Basketball" },
{ ID: "play.soccer", Name: "Soccer" }
]
}
];
return (
<div>
{results.map((data, index) => (
<ul key={data.ID}>
<li>
<div>{data.Name}</div>
{data.subs.length &&
data.subs.map((innerData) => (
<ul key={innerData.ID}>
<li>
<div>{innerData.Name}</div>
</li>
</ul>
))}
</li>
</ul>
))}
</div>
);
};
export default Salary;
Resultsis an array of objects. When you are mapping Results array you will get object indatavariable. But in your data object there is no key with the name ofkey.