I’m using lodash and have this code right now
data: _(responseData.data)
.pick(['title', 'layout', 'slug', 'author', 'seo', 'css', 'js'])
.mapKeys((value, key) => _.camelCase(key))
.value()
Some of the values can be returned as null from the database. I would like to replace null values with an empty string -> ” but I’m not sure how to chain another function to above chain.
2
Answers
You can use
||
OperatorUse
_.mapValues()
to iterate the values, and check with_.isNull()
if the value isnull
.Note: if you want to handle
undefined
values as well, replace_.isNull()
with_.isNil()
.