How to dynamically change the key name in an array of objects?

Is there a way to change the key names in an array of object?

Code:
List of value to change the key name.

var keys = {
    id:'identifier',
    facility:'site',
    status:'info',
    date:'days'
};

Array of object to change the key names

var arrayObj = [{
    id:'jr210',
    facility:'earth',
    status:'sample info',
    date:'Feb 29, 2020'
},
{
    id:'tl980',
    facility:'mars',
    status:'sample info',
    date:'Jan 15, 2020'
}]

Expected output:

var newArrayObj = [{
        identifier:'jr210',
        site:'earth',
        info:'sample info',
        days:'Feb 29, 2020'
    },
    {
        identifier:'tl980',
        site:'mars',
        info:'sample info',
        days:'Jan 15, 2020'
    }]

Leave a Comment