Skip to content

Instantly share code, notes, and snippets.

@davidalves1
Created September 26, 2025 16:46
Show Gist options
  • Save davidalves1/fbba8fc660266dd42a09d651f712efa0 to your computer and use it in GitHub Desktop.
Save davidalves1/fbba8fc660266dd42a09d651f712efa0 to your computer and use it in GitHub Desktop.
Javascript Helper Functions
// Retrieves a nested property from an object using a dot-notation key string.
const getDeepPropertyObject = (key, obj) => {
const steps = key.split('.')
return steps.reduce((curr, key) => {
if (!curr) {
return obj[key]
}
return curr[key]
}, null)
}
// Example
console.log(getObjectItem('user.address.street', {
user: {
name: 'David',
address: {
street: 'Rua AB',
number: 100
}
}
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment