-1

I have my json object array as

 {
  "_index": [
    "houseid"
  ], 
  "added": [
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }
  ], 
  "changed": [], 
  "removed": [
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }, 
    {
      "description": "detail about column", 
      "houseid": "la 123", 
      "\ufeffID": "154"
    }
  ]
}

I want to apply a loop so i can present details for added, removed changed as below: description houseid effid detail about column la 123 154 detail about column la 123 154

wingskush
  • 534
  • 1
  • 6
  • 22

2 Answers2

0

just import with some name, and get what you want.

import data from '../../result/result.json';

/* somewhere */
let to-add = data.toadd; // get field what you want.
godsenal
  • 387
  • 2
  • 12
0

You probably would want to use the forEach method of the lodash library. It will give you freedom to loop over the keys of objects as well.

_.forEach(object, (value, key) => {
    //do operations on value and key
})

If you need to render in react by looping over elements, you probably want to do something like this:

render(){
    return (
        <div>
        {_.map(elements, (item) => {
            <div>{item.name}</div>
        })}
        </div>
    );
}

You can make this work for table too. You can refer to this answer as well.

Ajay Gaur
  • 5,140
  • 6
  • 38
  • 60