Используйте Array.reduce()
и String.toUpperCase()
, как показано ниже
var obj = {
'application': "BP 9ALT 8 123",
'address': "935 HAMPTON CRES",
'unit': null,
'status': "COMPLETED -ALL INSP SIGNED OFF"
}
var resultOne = Object.entries(obj).reduce(function(acc, value) {
acc[value[0].charAt(0).toUpperCase() + value[0].slice(1)] = value[1];
return acc;
}, {});
// Updated
// In the reduce anonymous function, instead of value you can place [key, value]. So there will be no indexing
var resultTwo= Object.entries(obj).reduce(function(acc, [key, value]) {
acc[key[0].toUpperCase() + key.slice(1)] = value;
return acc;
}, {});
console.log(resultOne);
console.log(resultTwo);