Traversing through a Javascript Object

Damian
Coding Snippets
Published in
1 min readNov 15, 2017

I’ve started working with Firebase on a project and one of the interesting quirks with storing json data in its real-time database is that objects cannot have any properties that are undefined (you get “ Error: Firebase.set failed: First argument contains undefined in property”). They have to be stored as null instead.

However, after stackoverfloogling the problem i found all posted code snippets failed for my use case. So, here’s one i wrote: it recursively traverses the objects properties, including arrays and inspects all sub objects as well replacing properties that are undefined with null.

--

--

Damian
Coding Snippets

I’m a software architect for my day job and work on a lot of side projects around mobile tech in my free time.