Clear Whitespace dari Object JavaScript
var obj = {
" employee name": "Sumit Vishwakarma",
"employee id ": 001,
"email ": "[email protected]",
"mobile no": 9999999999,
};
Object.keys(obj).forEach((key) => {
var replacedKey = key.trim().toUpperCase().replace(/\s\s+/g, "_");
if (key !== replacedKey) {
obj[replacedKey] = obj[key];
delete obj[key];
}
});
console.log(obj);
result
EMAIL: "[email protected]",
EMPLOYEE ID: 1,
EMPLOYEE_NAME: "Sumit Vishwakarma",
MOBILE_NO: 9999999999
}
Precious Pygmy