I want to loop through a nested object and modify each key (delete first character).
The following code iterates through the whole object but does not modify the key. The Object still looks the same after running the function.
const removeFirstCharacterOfKey = (obj) => {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object') {
if(Array.isArray(obj[key])) {
return;
}
return removeFirstCharacterOfKey (obj[key]);
}
key = key.substring(1);
});
}
A possibility would also be to create a new object with modified keys. Is it possible to achieve this?