I was trying to access key, values from the below array
I am trying to access keys inside the fields object and value from the model inside keys object
formFields = [
{
"title": "Criteria Details",
"columns": 2,
"fields": {
"criteriaName": {
"type": "text",
"label": "Criteria Name",
"id": 'criteriaName',
"model": "CRITERIA 1",
"required": true,
"show": true,
"rules": [
v => !!v || 'Criteria Name is required',
]
},
"criteriaType": {
"type": "select",
"label": "Criteria type",
"id": "criteriaType",
"options": ['Dependent', 'Independent', 'Static'],
"model": "Dependent",
"required": true,
"rules": [
v => !!v || 'Criteria Type is required',
],
"show": true,
},
"table": {
"type": "select",
"label": "Table",
"id": "table",
"options": ["Table1"],
"model": "Table1",
"required": true,
"rules": [
v => !!v || 'Table is required',
],
"show": true,
},
"column": {
"type": "select",
"label": "Column",
"id": "column",
"options": ["Column1"],
"model": "Column1",
"required": true,
"rules": [
v => !!v || 'Column is required',
],
"show": true,
},
"joinType": {
"type": "select",
"label": "Join Type",
"id": "joinType",
"options": ["AND", "OR"],
"model": "OR",
"required": true,
"rules": [
v => !!v || 'Join Type is required',
],
"show": true,
},
"operator": {
"type": "select",
"label": "Operator",
"id": "operator",
"options": ["<", "<=", "<>", "=", ">=", ">", "EXISTS", "IN", "IS NOT NULL", "NULL", "LIKE", "NOT EXISTS", "NOT IN", "NOT LIKE"],
"model": ">=",
"required": true,
"rules": [
v => !!v || 'Operator is required',
],
"show": true,
},
"valueType": {
"type": "select",
"label": "Value Type",
"id": "valueType",
"options": ["Dependent SQL", "SQL", "VALUE"],
"model": "SQL",
"required": true,
"rules": [
v => !!v || 'Value Type is required',
],
"show": true,
},
"dataType": {
"type": "select",
"label": "Data Type",
"id": "dataType",
"options": ["DATE", "NUMBER", "STRING"],
"model": "NUMBER",
"required": true,
"rules": [
v => !!v || 'Data Type is required',
],
"show": true,
},
"format": {
"type": "text",
"label": "Format",
"id": "format",
"model": "Config",
"required": false,
"show": true,
},
"parameterMandatory": {
"type": "select",
"label": "Parameter Mandatory",
"id": "parameterMandatory",
"options": ["NO", "YES"],
"model": "YES",
"required": true,
"rules": [
v => !!v || 'Parameter Mandatory is required',
],
"show": true,
},
"link": {
"type": "select",
"label": "Link",
"id": "link",
"options": ["KB"],
"model": "KB",
"required": false,
"show": true,
},
"sequence": {
'type': "text",
"label": "Sequence",
"id": "sequence",
"model": "SEQ1",
"required": true,
"rules": [
v => !!v || 'Sequence is required',
],
"show": true,
},
"value": {
"type": "description_notes",
"label": "Value",
"id": "value",
"model": "VAL",
"required": true,
"rules": [
v => !!v || 'Value is required',
],
"show": true,
}
}
},
{
'title': "Notes",
"columns": 1,
"fields": {
"description": {
"type": "description_notes",
"label": "Description",
"id": "description",
"required": false,
"model": 'abcde',
"show": true,
}
}
}
]
****The Output i was trying is like this.**** How to access the keys and values from the above array like this. Which method we need to use
criteriaDetails: [
{"criteriaName": "CRITERIA 1"},
{"criteriaType": "Dependent"},
{"table": "Table1"},
{"column": "Column1"},
{"joinType": "OR"},
{"operator": ">="},
{"valueType": "SQL"},
{"dataType": "NUMBER"},
{"format": "Config"},
{"parameterMandatory": "YES"},
{"link": "KB"},
{"sequence": "SEQ1"},
{"value": "VAL"},
{"description": "abcde"}
]
I tried below code
const field = this.formFields.map(field => {
return Object.entries(field.fields)
})
console.log(field)
how can I achieve this? How to solve this. Please help
Thanks..
criteriaDetails? Or do you want to repeat this for every item in your array?criteriaName,criteriaTypein a specific order (same as the input object from top to bottom). If that order is critical then you can't use any of the given answers because Object.entries, Object.keys,for ... in/ofto get key/values of an object does not guarantee any order. In fact it states you'll get them in an arbitrary order