I'm trying to remove the extra space inside of the object value.
const object = {
primaryInformation: {
firstName: "John Doe",
lastName: "Doe Space"
}
}
Is there any simplest way to remove the extra space between the words of object value using map?
Expected Output
firstName: "John Doe",
lastName: "Doe Space"
Based on the object structure in your question, I've written this loop.
const object = {
primaryInformation: {
firstName: "John Doe",
lastName: "Doe Space"
}
};
for (const key in object) {
const value = object[key];
for (const key2 in value) {
const string = value[key2];
value[key2] = string.replace(/ +/g, " ");
}
}
console.log(object);