I'm trying to get an object value by passing a variable to a function, but I'm not sure how to do this with a multi layer object. It looks like this:
var obj = {
field1: { name: "first" },
field2: { name: "second" }
};
var test = function(field){
//sorting function using obj[field]
//return results
};
With the above, the following works:
var result = test("field1");
This sorts using the object {name: "first"} but say I want to use just the name value. I can't do this:
var result = test("field1.name");
What is the correct way to do this?
test("field1.name");would meanobj["field1.name"];return obj[field] && obj[field].name;