I am attempting to write a helper function for myself to check if a property is inside of a given OBJECT. For my own use case, if I come across an array, then I only have to obtain the first (0 index) array to continue. My helper function is to return a boolean value since it is only checking to see if the provided string will work (or not).

Given the OBJECT:

```
{'object': {
        "promotion": {
            "items": [{
                "startAndEndDate": {
                    "startDate": "2017-11-10",
                    "endDate": "2017-11-29"
                },
                "amount": {
                    "discount": 12
                }
            }]
        }
    }
};

```

My function:

```
var propertyInObjectFuncUtil = function (string, obj) {
            var substringArray = string.split('.');

            if (substringArray.length) {
                try {
                    substringArray.reduce(function (prev, curr) {
                        if (curr in prev) {
                            return prev[curr];
                        } else if (curr in prev[0]) {
                            return prev[0][curr];
                        } else {
                            throw ('These are not droids you are looking for...');
                        }
                    }, obj);

                    return true;
                } catch (error) {
                    console.error(error);
                    return false;
                }

            }
        };

```

Attempting to make it work with the following:

```
var example1 = propertyInObjectFuncUtil('object.promotion.items.amount.discount',obj) // true
var example2 = propertyInObjectFuncUtil('object.promotion.itemss',obj) // false
var example3 = propertyInObjectFuncUtil('object.promotion.items.startAndEndDate.endDates',obj) //false

```

However I am getting this TypeError:
`TypeError: Cannot use 'in' operator to search for 'itemss' in undefined`