Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const arr = {
- a: 4,
- b: 6,
- c: { x: 9, y: 8 }
- }
- const x = keyObjectFinder(this.arr, 'c.x');
- console.log('result is ' + x);
- helper.js
- export function keyObjectFinder(obj, value) {
- if (typeof obj === 'object' && obj.constructor === Object) {
- for (const key in obj) {
- if (obj.hasOwnProperty(key)) {
- let x = obj[value];
- return x;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement