Skip to content
Advertisement

Javascript How to update all Property Names in nested object

I would like to return a new object with the updated property names in the nested object.

For example in the fakeData below, I would like to update all the property names from:

JavaScript

The data that I am trying to update :

JavaScript

So far I’ve tried to use the recurrsion to do this but the subtask are not updating correctly

JavaScript

Advertisement

Answer

This is a short solution it return a new array without changing the existing one.

It use recursion and uses the Object.entries and fromEntries functions that do exactly that are perfect for this use case

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement