Skip to content
Advertisement

Flatten an object preserving certain Fields

I would like to flatten this object without flattening the keys $gt and $lt

JavaScript

the desired result would be

JavaScript

I have tried using flat library by specifying maxDepth of 2 but only works for gross_floor_area key

Advertisement

Answer

This will return the flattened object, without mutating the original object.

JavaScript

It doesn’t work for all keys starting with $, as you mentioned in the comment to your question, only $gt and $lt. More specifically, it won’t flatten the object that contains these two keys.

FYI, this was pretty much generated by GitHub Copilot. In case you use it, it’s very helpful for achieving this kind of goals.

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