0

I got data.js file with some basic info for food like:

export default [
    {
        "name": "Crock Pot Roast",
        "information":[
            {
                "date":"24 July 2019",
                "type": "Main dish",
                "difficulty": "Easy",
                "time": "~50",
            }
        ],
        "ingredients": [
            {
                "quantity": "1",
                "name": " beef roast",
                "type": "Meat"
            }
        ],
        ...
        Some more data
        ...
    }
   ]

I want to create list on react that can get all elements from data.information which function will be correct to use?

I'm getting the data like this:

const getData = data.map(food => {
    return (
        <div key={food.name}>
            <span>{food.name}</span>
            <div>
                <div>
                    <img src={food.imageURL} alt={food.name} />
                    <div>
                        <ul>{getFoodInformation}</ul>
                    </div>
                </div>
            </div>

            <div>food ingredients</div>

            <div>food recipe</div>
        </div>
    );
});

but I can't use food.information.map to create list like:

<ul>{food.information.map((info) => <div key={info.date}>{info}</div>) }</ul>

Any ideas maybe to use another function not map?

iraj jelodari
  • 3,118
  • 3
  • 35
  • 45
A.Salim
  • 11
  • 1
  • Does this answer your question? [How to iterate over a JavaScript object?](https://stackoverflow.com/questions/14379274/how-to-iterate-over-a-javascript-object) – segFault Feb 22 '20 at 02:29
  • What does your ideal/expected HTML look like for the value of `{getFoodInformation}` ? Should each property be contained in a separate `
  • ` ? – segFault Feb 22 '20 at 02:33