I am working with JSON data:
[
{
"name": "Person1",
"a_miles": "110 mi"
},
{
"name": "Person2",
"b_miles": "22 mi"
},
{
"name": "Person3",
"a_miles": "552 mi"
}
]
I need to rename a_miles or b_miles to "total" , but can't seem to get .map() to work since it won't allow multiple keys to 1 final key. Each item with have either A or B as well.
This is what I tried so far:
.data(function(data) {
console.log('checking for KMs');
for(key in data) {
console.log(key);
if(data[key].includes(' km')){
console.log('KM found, deleting %s', key)
delete data[key];
}
}
//console.log(data)
savedData.push(data);
})
.done(function() {
var formattedJson = savedData.map(({
name,
a_miles:total,
b_miles:total
}) => ({
name,
total
}));
Maybe I'm over complicating things, I just need to have a total key/value that replaces a or b so it's consistent through the whole array result.