Here’s a way:
function getKey(key, obj) {
return key.split('.').reduce(function(a,b){
return a && a[b];
}, obj);
}
getKey('foo.bar', obj); //=> "I want this"
More Related Contents:
- How do I add a delay in a JavaScript loop?
- FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory in Ionic 3
- How to make cross domain request [duplicate]
- When serving JavaScript files, is it better to use the application/javascript or application/x-javascript
- How to set locale in DatePipe in Angular 2?
- JavaScript – why Array.prototype.fill actually fills a “pointer” of object when filling anything like ‘new Object()’
- Applying className/onClick/onChange not working on Custom React Component
- orderBy multiple fields in Angular
- ES6 Promises – something like async.each?
- this.setState isn’t merging states as I would expect
- Mongoose the Typescript way…?
- In javascript how can I dynamically get a nested property of an object
- Why are objects’ values captured inside function calls?
- Why is the variable holding the input value always logged as empty?
- How to ONLY trigger parent click event when a child is clicked
- Can’t type in React input text field
- jQuery min/max property from array of elements
- UI-router interfers with $httpbackend unit test, angular js
- How can I detect when a new element has been added to the document in jquery?
- onchange event not fire when the change come from another function
- Resize a Base-64 image in JavaScript without using canvas
- How do I count a JavaScript object’s attributes? [duplicate]
- Best way to alphanumeric check in JavaScript
- What is the difference between `firstChild` and `firstElementChild`?
- How to extract extension from filename string in Javascript? [duplicate]
- ng-repeat with ng-transclude inside a directive
- How to get difference between 2 Dates in Years, Months and days using moment.js
- How to resolve the Syntax error : await is only valid in async function?
- How do I export multiple html tables to excel?
- querySelectorAll.style does not work