1

In my render() method i need to parse nested json objects. See the portion of render and json structure below. I access Last Name with {params.name_last}. How will i access items under team, like team.name_first

render() {
        let { params } = this.props.navigation.state
        <Text>{params.name_last}</Text>
}

[
	{
		"id": 1,
		"name_first": "Name first 1",
		"name_middle": "",
		"name_last": "Name last 1",
		"name_suffix": "",
		"phone": "888-8888",
		"fax": "888-8888",
		"updated_at": "2015-11-02T21:42:42.000Z",
		"team": [
			{
				"id": 16,
				"name_first": "aaa",
				"name_middle": "",
				"name_last": "bbb",
				"name_suffix": ""
			},
			{
				"id": 28,
				"name_first": "aaa",
				"name_middle": "",
				"name_last": "bbb",
				"name_suffix": ""
			},
			{
				"id": 29,
				"name_first": "aaa ",
				"name_middle": "",
				"name_last": "bbb",
				"name_suffix": ""
			}
		]
	}
 ]

1 Answer 1

1

Since team is an array, you need to either access a specific entry in the array, or iterate over the entire thing.

To reach a specific property in the nested array entry (assuming you want the object at index i):

params.team[i].name_first

To create an array of first names:

params.team.map(x => x.name_first)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.