0

What's the most efficient way to use reflection on a js object? Here's an example data structure:

  var data = {
    NortheastRegion:
    {
        RegionName: 'Northeast',    
        SomeGeneralRegionInfo: 'Info1'
    }
    SoutheastRegion:
    {
        RegionName: 'Southeast',    
        SomeGeneralRegionInfo: 'Info2'      
    }
  }

Let's say I'd like to use a reflection style similar to this:

var regionName = 'SoutheastRegion';
var region = data[regionName];
var info = region.SomeGeneralRegionInfo;

What would be the most efficient way to do something like this?

  • 2
    1. `Here's an example data structure` this is not syntactically correct 2. I don't think what you call reflection is really reflection. 3. What do you mean by "efficient"? 4. Why do you think your proposed way of doing this is "inefficient"? – VLAZ Sep 23 '16 at 20:17
  • 1
    FYI, the syntax error is a missing comma before `SoutheastRegion`. – Barmar Sep 23 '16 at 20:18
  • What's inefficient about what you've already got? What is the problem you're trying to solve? – Pointy Sep 23 '16 at 20:19
  • What you're calling reflection is just dynamically accessing properties. Reflection means asking the system for information about itself, such like using `Object.keys(data)`. – Barmar Sep 23 '16 at 20:20

0 Answers0