I have this function :
const id = await this.$axios(config)
.then(({ data : { user : { profile : { profileId } }}}) => profileId || 0 )
To make it simple
const id = ({ a : { b : { c : { id } } } } ) => id || 0
The best way to null check this without crashing in runtime is
const id = ({ a : { b : { c : { id } = {} } = {} } = {} } = {} ) => id || 0
which is as you can see, not as readable as this
const id = (data) => a?.b?.c?.c?.id || 0
Is there another way to destructure even if the property might not exist or if the object is another type ?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/XehMLIb
Comments
Post a Comment