-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

0

2 Answers 2

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.
Sign up to request clarification or add additional context in comments.

2 Comments

yes i cant access to-add as to-add = data.toadd
but i want to iterate it in a loop so i can publish it in a table under <tr> and <td> tag for toadd, removed, changed
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.

1 Comment

i have updated the question. and map is not recognized in my table.component.js

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.