I'll start with an acknowledgement that there are many similar questions and I've reviewed all of them and tried their suggestions without success. I have a simple array of objects:
data_array = [{'prop1': 64, 'prop2': 'Y', 'prop3':83},
{'prop1': 62, 'prop2': 'N', 'prop3':105},
{'prop1': 89, 'prop2': 'Y', 'prop3':75},
{'prop1': 74, 'prop2': 'N', 'prop3':23}]
I have another array that lists some new names for the properties and the order that I need the properties in
renaming_array = [{'order' : 1, 'oldName' : "prop1", 'newName' : "Condition"},
{'order' : 2, 'oldName' : "prop2" , 'newName' : "Significance"},
{'order' : 3, 'oldName' : "prop3" , 'newName' : "Lower Bound"}]
For each object in the data_array, I need to rename the properties and reorder them. I've gone about extracting the keys of each array and ordering them according to the order in renaming_array and that works well (I've done that a variety of ways). But every time I convert that sorted array back into an object that contains the values from the original data_array, the objects get resorted as the originally were. Most forums I've found suggest this method:
const sorted = Object.keys(obj)
.sort()
.reduce((accumulator, key) => {
accumulator[key] = obj[key];
return accumulator;
}, {});
but it has the same problem as I described above. I'm open to working with D3 methods, if there are any that would help with this problem. This seems like it shouldn't be this difficult!