0

I'm new to reactJS and I need to achieve a certain result. I have an array-

{
  "column_01": 11,
  "column_02": 123,
  "column_03": "TEST0001.iml",
  "column_04": "TEST0001.qsl",
  "column_05": "2018-11-13 01:04:40",
  "column_06": "PASSED",
  "column_07": "4/0/4"
}

I need to add another set similar structure to that data and add up these to an array, such result should be:

{
  "column_01": 11,
  "column_02": 123,
  "column_03": "TEST0001.iml",
  "column_04": "TEST0001.qsl",
  "column_05": "2018-11-13 01:04:40",
  "column_06": "PASSED",
  "column_07": "4/0/4"
},
{
  "column_01": 12,
  "column_02": 124,
  "column_03": "TEST0001.imx",
  "column_04": "TEST0001.qsx",
  "column_05": "2018-11-13 01:04:40",
  "column_06": "PASSED",
  "column_07": "4/0/5"
}

…. how do I achieve that to in react js? so far these are my efforts but haven't succeed yet:

onTableViewChange(result){
    const arr = [];
      if (result) {
          console.log(result.original);
          arr.push(result.row);
     }
Just code
  • 13,553
  • 10
  • 51
  • 93
Gendric
  • 3
  • 6
  • Check this out: https://stackoverflow.com/a/46179203/263081 – Just code Nov 15 '18 at 04:53
  • *"I have an array"* ...not really. The first block in question shows only an object literal....no array. As for what you do in last block you haven't shown how you use the new `arr` after you push into it – charlietfl Nov 15 '18 at 04:55

1 Answers1

0

You haven't provided a lot of details, but arr should be defined in your state, and then you should update it using setState like this

this.setState(prevState => { 
  return { arr: [...prevState.arr, result.row] }
})
m0meni
  • 16,006
  • 16
  • 82
  • 141