我的反应式数组中有以下值:
ADVERSE_POSESSION: ""
PRIMARY_RESIDENCE: "Yes"
SUBJECT_TO_TENANCY: "Tenancy"
如何遍历这些字段,以便每个字段都是数组中自己的对象?
我想要的输出是:
{
"fieldId": "ADVERSE_POSESSION",
"value": ""
},
{
"fieldId": "PRIMARY_RESIDENCE",
"value": "Yes"
},
{
"fieldId": "SUBJECT_TO_TENANCY",
"value": "Tenancy"
}
答案 0 :(得分:0)
重新映射它。这是一个例子。
const formValue = {
ADVERSE_POSESSION: "",
PRIMARY_RESIDENCE: "Yes",
SUBJECT_TO_TENANCY: "Tenancy",
}; // Likely this.formGroup.getRawValue()
const array = Object.keys(formValue).map(key => ({ fieldId: key, value: formValue[key] }));
console.log(array);