I am getting this object :
JavaScript
x
11
11
1
"contributionData": {
2
"Contribution 1": [
3
4,
4
4
5
],
6
"Contribution 2": [
7
1,
8
1
9
]
10
}
11
I want this kind of table after iteration.
JavaScript
1
3
1
contribution1 | 4 | 4 |
2
contribution2 | 1 | 1 |
3
I’ve converted it to array :
JavaScript
1
6
1
let result = [];
2
3
for(let i in this.state.testData) {
4
result.push([i, this.state.testData[i]]);
5
}
6
console log after converting it to array
JavaScript
1
4
1
<tr>
2
<td>{this.state.result}</td>
3
</tr>
4
I want to fill this data in table format I am working on React js, I want to do this in javascript.
Any help would be appreciated.
Advertisement
Answer
Try this one.
JavaScript
1
24
24
1
let result = []
2
let data = {
3
"Contribution 1": [
4
4,
5
4
6
],
7
"Contribution 2": [
8
1,
9
1
10
]
11
}
12
Object.keys(data).map((item) => {result.push([item].concat(data[item]))})
13
console.log(result);
14
15
{
16
results.map(item, i)=> (
17
<tr key={i}>
18
{item.map(val, index) => (
19
<td key={"row" + index}>{val}</td>
20
)}
21
</tr>
22
)
23
}
24