This object contains --> array --> object. Using for/foreach or another method I need to iterate the ROW in the table. This is React JSX code. Could someone please help me understand what to do?
a:{
bb: [{}],
cc: [{}],
dd: [{}]
}
I need to iterate object "a" using dynamic "key" and render JSX Row code in a Table using attribute in side the nested objects.
render() {
const {
data: {
drivers: { user, month, year, createdAt },
},
} = this.props;
let DriverCommissionResults = {};
let recent = "";
let combinedUser = {};
DriverCommissionResults = {
"Jane": 200,
"Ann": 100,
"Kevin": 50,
}
for (const [key, value] of Object.entries(DriverCommissionResults)) {
combinedUser[`${key}`] = user.reduce(function (filtered, option) {
if (option.username === key) {
var someNewValue = {
userId: option.userId,
username: option.username,
createdAt: option.createdAt,
ranking: option.ranking,
year: option.year,
month: option.month,
handle: option.handle,
initialSalary: option.initialSalary,
salary: option.salary,
drunkenPesentage: option.drunkenPesentage,
newTotalCommission: value,
};
filtered.push(someNewValue);
}
return filtered;
}, []);
}
for (const [key, value] of Object.entries(DriverCommissionResults)) {
recent = combinedUser[`${key}`].map((filteredPerson) => (
<RowComponent
newSalary={filteredPerson.initialSalary}
key={filteredPerson.userId}
member={filteredPerson}
card={cardMode}
newTotalCommission={filteredPerson.newTotalCommission}
/>
));
}
return (
<Fragment>
<table>
<thead>
<tr>
<th>Handle</th>
<th>InitialSalary</th>
<th>Salary</th>
</tr>
</thead>
<tbody>{recent}</tbody>
</table>
</Fragment>
}
console.log(combinedUser);
{Jane: Array(1), Ann: Array(1), Kevin: Array(1)}
{
Jane: [{handle: "Jane", username: "Jane", salary: 40000, initialSalary: 40100, }],
Ann: [{handle: "Ann", username: "Ann", salary: 50000, initialSalary: 50100,}],
Kevin: [{handle: "Kevin", username: "Kevin", salary: 30000, initialSalary: 30100,}],
}
Output
Handle InitialSalary Salary
Kevin 30000 30100
Expected Output
Handle InitialSalary Salary
Jane 40000 40100
Ann 50000 50100
Kevin 30000 30100