I have a react js/javascript object with a bunch of entries and the general format looks like this:
export const myJsonArray = [
{
headerName: 'Id',
headerTooltip: 'Id',
field: 'id',
width: myColWidth,
sortable: true,
filter: true,
},
{
headerName: 'Bank Code',
headerTooltip: 'Bank Code',
field: 'bankCode',
width: myColWidth,
sortable: true,
filter: true,
autoHeight: true,
editable: true,
},
]
I want to extract only the field values and build a new object that looks like:
{
id: '',
bankCode: '',
...
fieldn: ''
}
With the field name as the keys and an empty string as the value. Trying to start with something like this to extract just the field names.
let arr = [];
myJsonArray.map((column) => {
arr.push(column.field);
});
In Java there is a JSONObject and you can add key/value pairs to an object like this:
JSONObject jo = new JSONObject();
jo.put("firstName", "John");
There must be a simple way to dynamically build an object in javascript/react js but surprisingly not finding what I need. I'm thinking this can be done in two or three lines of code. What is the recommended way to handle this transformation in javascript or react js?