I have a nested object, something similar to this:

```
var obj = {
    "prop1": {
       "prop1A": "A",
       "prop1B": {
                  "prop1BA": "BA"
       }, 
       "prop1C": "C"
    }  
};

```

My final goal is to filter this object to specific pre defined keys, according to another schema object, for example:

```
var filterSchema = {
    "prop1":["prop1A", {"prop1B":["prop1BA"]}]
};

```

(The filter keys are predefined, I can structure this object differently if you have a better idea...

The output should be an array. In our case:

```
["A","BA"]

```

I managed to do this using recursion over the object. I was wondering if there is more elegant way for achieving this (tried using jQuery's map/extend with no luck)

**EDIT**
I know that this is a "N" level problem which should be solved by recursion. The difference here is that I have the pre-defined filter which already have the "N" levels. So I though maybe I can filter the Objet using the filter Array and than convert it into an array.

**EDIT2**
Thanks you all for the different answers. This is my own solution for the problem (which I was looking for a more elegant one in the beginning):
[My solution](http://jsbin.com/fimegajale/3/edit?js,console)

```
            var obj = {
        "prop1": {
           "prop1A": "A",
           //"prop1B": {
           //           "prop1BA": "BA"
           //}, 
           "prop1C": "C",
           "prop1D": "D",
           "prop1E": {"prop1E1": "444"}
        },
        "prop2": "12345"
    };

    var schemaObj = {
        "prop1": {
           "prop1A": "true",
           "prop1B": {
                      "prop1BA": "true"
           }, 
           "prop1C": "true"
        },
        "prop2": "true"
    };

var resultsArray = [];
var keys = Object.keys(schemaObj);
for(var i=0;i<keys.length;i++){
  if(obj[keys[i]]){
      parser(schemaObj[keys[i]], obj[keys[i]]);    
  }
}

function parser(v,o){
  if( typeof v === "string" ){
      resultsArray.push(o);    
  }
  else{
    var keys2 = Object.keys(v);  
    for(var j=0;j<keys2.length;j++){
      if(o[keys2[j]]){
        parser(v[keys2[j]], o[keys2[j]]);
      }
    }
  }
}

console.log(resultsArray);

```

Just a reminder about the question - **I already had the recursion solution**. I am looking for a different solution