Question: I have created a function to recursively find empty values in a nested array.

The function returns the correct value at first but seems to reset it to the input value before returning the result.

What am I missing?

Here is my code:

```js
const obj = [
  {
    mainContact: true,
    contactName: "",
    emailId: "abc@gmail.com",
    contactAddress: [
      {
        addressType: "",
        county: "U.K.",
        postCode: "MK7 6BZ",
        houseFlatNumber: 1
      },
      {
        addressType: "def",
        county: "France",
        postCode: "123MKO",
        houseFlatNumber: "223"
      }
    ],
    phoneDetails: [
      {
        notes: "",
        phoneNumber: "1234567899",
        countryCode: "44",
        priority: "1"
      },
      {
        notes: "Lorem ipsum",
        phoneNumber: "1112223331",
        countryCode: "48",
        priority: "2"
      }
    ]
  }
];

function validObject(obj, isOk) {
  for (var propName in obj) {
    if (typeof obj[propName] === "object") {
      this.validObject(obj[propName], isOk);
    } else if (
      obj[propName] === null ||
      obj[propName] === undefined ||
      obj[propName] === ""
    ) {
      isOk = false;
      break;
    }
  }
  return isOk;
}

console.log(validObject(obj), true);
// This should return false but it returns true although it first hit the return isOk line
// with a false value then set it back to true

```

Any help would be much appreciated.

Thanks.

Answer: 
The thing about recursion is that you have to return the value from your recursive call. That means that you call the function from inside itself, then handle the return value accordingly. 

Here's my interpretation of your function, where I add a simple base case to check if the passed value is `null`, `undefined`, or empty string.

```
function isValidObject(obj) {
  // Base case
  if (obj[propName] === null || obj[propName] === undefined || obj[propName] === '') {
    return false;
  }

  // Recurse through each item in object
  if (typeof obj === "object") {
    for (var propName in obj) {
      if (!isValidObject(obj[propName]) {
        return false;
      }
    }
  }
  return true;
}

```

*Notice that this allows you to get rid of the boolean parameter that you pass into your function and instead just return false when the first is found*.
Thanks to James McGuigan, my edited version is as below:

```
       isValidObject(obj) {

         for (var propName in obj) {
            if( typeof obj[propName] === "object" ) {
                if( this.isValidObject(obj[propName]) === false || 
                     obj[propName] === null || 
                     obj[propName].length === 0 ) 
                {
                     return false;
                }
            } 
            else if (
                      obj[propName] === null      || 
                      obj[propName] === undefined || 
                      obj[propName] === '' 
                    ) {
                         return false;  
                      }
            }
            return true;  

        }

```