javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
object.entries render component react
{
areas: ['areaid_0', 'areaid_1', 'areaid_2'],
areaDetails: {
'areaid_0': {title: 'Some title', isSelected: false},
'areaid_1': {title: 'Some title', isSelected: false},
'areaid_2': {title: 'Some title', isSelected: false}
}
}
When it comes to rendering you can do like,
this.state.areas.map(x => {
const areaDetail = this.state.areaDetails[x];
<Component key={x} {...areaDetail}... />
})
When you wants to update any object, you can do like,
this.state.areaDetails[x].isSelected = true;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us