 <p>Just make the value a <code>String</code> by concatenating an empty <code>String</code>:</p> <pre><code>function getObjects(obj, key, val, path) { var value = val + ""; for (var prop in obj) { if (prop == key &amp;&amp; obj[key].toLowerCase().match(value)) { result.push(passName); matchFlag = 1; } } } </code></pre>