I need to find the key names on an array that includes 'id' as prefix and change them as 'id' as unique key. There will be more elements added from back-end to the array with id key names with many variations as possible.
- First find key names that include 'id'.
- Delete string that doesn't match with 'id' prefix.
Initial array:
const data = [
{
"name": "Name 01",
"description": "Name 02",
"createdDate": "",
"modifiedDate": null,
"status": false,
"idMapType": 1,
},
{
"name": "Name 01",
"description": "Name 02",
"createdDate": "",
"modifiedDate": null,
"status": true,
"idProjectStatus": 2,
}
]
Desired output:
const data = [
{
"name": "Name 01",
"description": "Name 02",
"createdDate": "",
"modifiedDate": null,
"status": false,
"id": 1,
},
{
"name": "Name 01",
"description": "Name 02",
"createdDate": "",
"modifiedDate": null,
"status": true,
"id": 2,
}
]