JavaScript not returning int ..at least not when I think it should be
<p>Assuming that <code>arr</code> is an array of objects.</p>

<pre><code>arr = // some items;

function findItem( source, item ) {
  return source.indexOf(item);
}
</code></pre>

<p>Now, I know the code is correct, it actually does find the right index, but I get an '<code>undefined</code>' response. However if I do this..</p>

<pre><code>function findItem( source, item ) {
  var i = 0;
  i = source.indexOf(item);
  return i;
}
</code></pre>

<p>I get the right index. </p>

<p>I've even tried.</p>

<pre><code>function findItem(source, item) {
 return parseInt( source.indexOf(item) );
}
</code></pre>

<p>and I still get an '<code>undefined</code>'.</p>

<p>Can someone tell me what in the world is going on?</p>

<h2>Okay, to make things a bit simpler, I'll post more code here.</h2>

<pre><code>        function init() {
            alert(discoverWithoutVar());
            alert(discoverWithVar());
        }
        function discoverWithoutVar() {
            var arr = [{ Name: "Stacey" }, { Name: "Ciel" }, { Name: "Derek" }, { Name: "Christi"}];

            // find the index of 'Ciel'
            arrayForEach(arr, function (e) {
                if (e.Name == "Ciel") {
                    return arrayIndexOf(arr, e);
                }
            });
        }
        function discoverWithVar() {
            var arr = [{ Name: "Stacey" }, { Name: "Ciel" }, { Name: "Derek" }, { Name: "Christi"}];

            var i = 0;
            // find the index of 'Ciel'
            arrayForEach(arr, function (e) {
                if (e.Name == "Ciel") {
                    i = arrayIndexOf(arr, e);
                }
            });

            return i;
        }
        function arrayForEach(array, action) {
            for (var i = 0, j = array.length; i &lt; j; i++)
                action(array[i]);
        }

        function arrayIndexOf(array, item) {
            if (typeof array.indexOf == "function")
                return array.indexOf(item);
            for (var i = 0, j = array.length; i &lt; j; i++)
                if (array[i] == item)
                    return i;
            return -1;
        }
</code></pre>
