hi guys I'm trying to extract data from this:
1) […]
0: {…}
__v: 0
_id: "5ba96b8ebffd923734090df4"
formID: "5ba96b83bffd923734090df0"
inputArr: Array(3) [ "value1", "value2", "value3" ]
labelArr: Array(3) [ "label1", "label2", "label3" ]
<prototype>: Object { … }
length: 1
<prototype>: Array []
I need to get to the array inside the data, which is this.state.inputData (what you see above is the content),
I tried
const labels = inputDataArr[0].labelArr.map((r, index) => {
return (
<tr key={index}>
<th>{index}</th>
<th>{r[index]}</th>
</tr>
);
but I get item undefined, anybody knows why?
EDIT : additional problem rendering :
renderData(i) {
const { inputDataArr } = this.state;
return (
!!inputDataArr.length &&
inputDataArr[i].inputArr.map((input, index) => (
<th key={index}>{input}</th>
))
);
}
countLength() {
const { inputDataArr } = this.state;
return !!inputDataArr.length && inputDataArr[0].inputArr.length;
}
runThrough() {
for (let i = 0; i < this.countLength; i++) return this.renderData(i);
}
render() {
const data = this.runThrough();
return (
<div className="app">
<table>
<tr>{this.renderLabels()}</tr>
{data}
</table>
</div>
);
}
}