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);
     }
2
  • Check this out: stackoverflow.com/a/46179203/263081
    – Just code
    Nov 15, 2018 at 4: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, 2018 at 4:55

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.