Skip to main content
added 839 characters in body
Source Link
Alexander
  • 1.4k
  • 5
  • 22
  • 44

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>
    );
  }
}

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?

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>
    );
  }
}
Source Link
Alexander
  • 1.4k
  • 5
  • 22
  • 44

extracting array inside an object thats inside an array

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?