0

I have a .json file like this:

import single from 'file.json'


{
"id": 4,
"code": 4508099576,
"important": [
            {
            "id": 4,
            "name": "services"
            }
        ]

}

I want to access "services" for render it. But the following syntax doesn´t work:

<span>Plans: {single.important.name}</span>
1
  • 2
    I think you need to learn a little more about Javascript, Datatypes, Arrays, Etc before to start to develop with React. {single.important[i].name} where i is the index. Commented Mar 3, 2018 at 18:41

2 Answers 2

1

important is an array and you need to access its first object. Your would write

<span>Plans: {single.important[0].name}</span>

In case if you want to render all the plans within the important array, you would make use of map like

<div>{single.important.map((obj) => {
   return  <span key={obj.id}>Plans: {obj.name}</span>
})</div>
Sign up to request clarification or add additional context in comments.

Comments

0

Important is an array. You need to access it with an index ex.

single.important[0].name

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.