I have this piece of code that removes characters such as whitespace from property names:
let result = rows.map(el => {
let resultobj = {};
Object.entries(el).map(([key, val]) => {
resultobj[key.split(" ").join("").replace(/\W+/g, '')] = val;
return resultobj;
} )
return resultobj;
})
There is a property named "AgendaItem", I would like to remove the word "Item" from the name, leaving only "Agenda". How can I add this requirement to the current code, above?
Thank you for your help, Erasmo
UPDATE - I tored the code below, to replace File # with Legistar, and LegistarID with Legistar
let result = rows.map(el => {
let resultobj = {};
Object.entries(el).map(([key, val]) => {
resultobj[key.split(" ").join("").replace(/\W+|Item$/g, '').replace("File #","Legistar").replace("LegistarID","Legistar")] = val;
return resultobj;
})
return resultobj;
})
console.log(result);
After execution, result contains:
0
:
{File: '75588', Ver: '1', Agenda: '1', BoardsCommissionsandCommittees: 'Public Comment', Type: 'Public Comment', …}
1
:
{File: '75590', Ver: '1', Agenda: '2', BoardsCommissionsandCommittees: 'Lake Update', Type: 'Miscellaneous', …}
2
:
{File: '75592', Ver: '1', Agenda: '3', BoardsCommissionsandCommittees: 'Booking Pace Update:', Type: 'Miscellaneous', …}
3
:
{File: '75594', Ver: '1', Agenda: '4', BoardsCommissionsandCommittees: 'Finance Report: ', Type: 'Miscellaneous', …}
4
:
{File: '75595', Ver: '1', Agenda: '5', BoardsCommissionsandCommittees: 'Director’s Report: ', Type: 'Miscellaneous', …}
5
:
{File: '75596', Ver: '1', Agenda: '6', BoardsCommissionsandCommittees: 'Announcement from the Chair: , Chair', Type: 'Miscellaneous', …}