I have the following input:
schema: [{
fields: [{
name: 'name',
type: 'text',
col: 10,
value: ''
}, {
name: 'description',
type: 'text',
col: 2,
value: ''
}]
}, {
fields: [{
name: 'password',
type: 'text',
col: 8,
value: ''
}, {
name: 'confirmPassword',
type: 'textarea',
col: 4,
value: ''
}]
}],
And I set the valuesobjects of nested arrays as follows:
updateField (name, value) {
this.schema.forEach((formGroup, index) => {
formGroup.fields.forEach(field => {
if (field.name === name) field.value = value
})
})
},
Is there a way to avoid using two nested ones forEach? (Without using any library like Lodash?)
source
share