i'm pretty new to react and javascript and i want to know how to iterate a list inside another list.
I have this json variable:
this.state = {
groups: [{
name: '',
permission: [{
name: ''
}]
}]
}
What I want to do is to count the number of elements the second list has, i did this following code but it sends the follwoing error, groups.map is not a function:
render() {
let permissionGroup = this.state.groups.map((groups) => {
let x = 0;
groups.map((permission) => {
x++;
})
})
return (
<div>
{this.state.groups.map((groups) => {
return (<li key={groups.code}>
<Card style={{ width: '20rem' }}>
<Card.Body>
<Card.Title>{groups.name}</Card.Title>
<Card.Subtitle className="mb-2 text- enter code heremuted">Permissions info</Card.Subtitle>
<Card.Text>
This group has {permissionGroup} permissions in it.
</Card.Text>
<Card.Link href="#">Add Permission</Card.Link>
<Card.Link href="#">Remove Permission</Card.Link>
</Card.Body>
</Card>
</li>)
})}
</div>