I have object like this :
let output =
[
{
Email: '[email protected]',
KolomB: 'Haha',
KolomC: 6,
' Kolom D ': '3.000.000',
KolomE: 2022-01-01T16:59:48.000Z
},
{
Email: '[email protected]',
KolomB: 'blabla',
KolomC: 6,
' Kolom D ': '3.000.000',
KolomE: 2022-01-01T16:59:48.000Z
}
]
I want to remove the spaces if occurs in keys inside the object.
this is my desired output :
output =
[
{
Email: '[email protected]',
KolomB: 'Haha',
KolomC: 6,
KolomD: '3.000.000',
KolomE: 2022-01-01T16:59:48.000Z
},
{
Email: '[email protected]',
KolomB: 'blabla',
KolomC: 6,
KolomD: '3.000.000',
KolomE: 2022-01-01T16:59:48.000Z
}
]
As you can see, i want to remove the space in Kolom D to be KolomD in output variable.
Here's what i've done before :
for (let i = 0; i < output.length; i++) {
Object.keys(output[i]).forEach(function(key) {
key = key.replace(/\s+/g, "").replace(/^\s+|\s+$/g, "")
})
}
but the output still not changing. How to push/changing the keys to the output ?
Please let me know if you need more information if it's still not enough to solve that problem
deleteoutputto my new object with new keys ?replace? I don't understand why the secondreplaceis necessary.