I have an array of objects from some api call. Each of these objects have a key named id. I want to change this id to post_id for each object in the array The first key in each object is id, so I have accessed index 0 in the code below.
Thanks in advance.
function changePostId(receivedData) {
receivedData.forEach(obj => {
var keys = Object.keys(obj);
var key = keys[0].replace(/^id/, "post_id");
tmp[key] = obj[keys[0]];
});
}
objnottemp.