Question: is there any function or any fast way to check if some value in our object startsWith e.g **asd**

Example:

```
let obj = { 
   'child' : {
      'child_key': 'asdfghhj'
    },
    'free': 'notasd',
    'with': 'asdhaheg'
  }

// check here if our obj has value that startsWith('asd')

```

Regards

Answer: 
Here is a function with mild ES6 usage:

```js
function startsWithRecursive(obj, needle) {
    return obj != null && 
        (typeof obj === "object"
            ? Object.keys(obj).some( key => startsWithRecursive(obj[key], needle) )
            : String(obj).startsWith(needle));
}

// Sample data
let obj = { 
    'child' : {
      'child_key': 'asdfghhj'
    },
    'free': 'notasd',
    'with': 'asdhaheg'
};
// Requests
console.log( 'obj, "asd":',    startsWithRecursive(obj, 'asd'    ) );
console.log( 'obj, "hello":',  startsWithRecursive(obj, 'hello'  ) );
console.log( 'null, "":',      startsWithRecursive(null, ''      ) );
console.log( 'undefined, "":', startsWithRecursive(undefined, '' ) );
console.log( '"test", "te":',  startsWithRecursive('test', 'te'  ) );
console.log( '12.5, 1:',       startsWithRecursive(12.5, 1       ) );
```

### Explanation:

The function is recursive: it calls itself as it goes through a nested object structure. The value passed as `obj` can fall in one of the following three categories:

1. It is equivalent to `null` (like also `undefined`): in that case neither a recursive call, nor a call of the `startsWith` method can be made: the result is `false` as this value obviously does not start with the given search string;
2. It is an object: in that case that object's property values should be inspected. This will be done through recursive calls. The `some` method makes sure that as soon a match has been found, the iteration stops, and no further property values are inspected. In that case `some` returns `true`. If none of the property values matched, `some` returns `false`;
3. It is none of the above. In that case we cast it to string (by applying the `String` function) and apply `startsWith` on it.

The value calculated in the applicable step will be returned as function result. If this was a recursive call, it will be treated as return value in the `some` callback, ...etc.

Note that this function also returns the correct result when you call it on a string, like so:

```
startsWithRecursive('test', 'te'); // true

```

### Non-Recursive Alternative

In answer to comments about potential stack limitations, here is an alternative non-recursive function which maintains a "stack" in a variable:

```
function startsWithRecursive(obj, needle) {
    var stack = [obj];
    while (stack.length) {
        obj = stack.pop();
        if (obj != null) {
            if (typeof obj === "object") {
                stack = stack.concat(Object.keys(obj).map( key => obj[key] ));
            } else {
                if (String(obj).startsWith(needle)) return true;
            }
        }
    }
    return false;
}

```
You may get away with something as simple as using a RegExp on a JSON string, something like

```js
var obj = {
  'child': {
    'child_key': 'asdfghhj'
  },
  'free': 'notasd',
  'with': 'asdhaheg'
};

function customStartsWith(obj, prefix) {
  return new RegExp(':"' + prefix + '[\\s\\S]*?"').test(JSON.stringify(obj));
}

console.log('obj, "asd":', customStartsWith(obj, 'asd'));
console.log('obj, "hello":', customStartsWith(obj, 'hello'));
console.log('null, "":', customStartsWith(null, ''));
console.log('undefined, "":', customStartsWith(undefined, ''));
console.log('"test", "te":', customStartsWith('test', 'te'));
console.log('12.5, 1:', customStartsWith(12.5, 1));
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.1/es6-shim.js"></script>
```

Update: Another recursive object walker that will work in a shimmed environment. This is just an example and it is easily customised.

```js
var walk = returnExports;
var obj = {
  'child': {
    'child_key': 'asdfghhj'
  },
  'free': 'notasd',
  'with': 'asdhaheg'
};

function customStartsWith(obj, prefix) {
  var found = false;
  walk(obj, Object.keys, function(value) {
    if (typeof value === 'string' && value.startsWith(prefix)) {
      found = true;
      walk.BREAK;
    }
  });
  return found;
}

console.log('obj, "asd":', customStartsWith(obj, 'asd'));
console.log('obj, "hello":', customStartsWith(obj, 'hello'));
console.log('null, "":', customStartsWith(null, ''));
console.log('undefined, "":', customStartsWith(undefined, ''));
console.log('"test", "te":', customStartsWith('test', 'te'));
console.log('12.5, 1:', customStartsWith(12.5, 1));
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.1/es6-shim.js"></script>
<script src="https://rawgithub.com/Xotic750/object-walk-x/master/lib/object-walk-x.js"></script>
```