r/badcode • • Dec 17 '21

typescript I don't know where to start

Post image
170 Upvotes

24 comments sorted by

View all comments

Show parent comment

16

u/[deleted] Dec 17 '21

Or maybe:

key.split('.').slice(0,4).reduce((acc, key) => acc[key] || null, data)

2

u/[deleted] Dec 17 '21

if you don't mind using a lib you can just _.get(object, path) and move on

1

u/[deleted] Dec 19 '21

Using libraries is overrated