Can someone help me understand if the functions in_array_orig and in_array_new are essentially the same? I'm also confused about the results when comparing arrays aArr1 and aArr2.
Could someone explain this to me? Thank you.
Below is a snippet of my test code:
function echo(s)
{
document.write(s);
}
function in_array_orig(oItem, aArray)
{
for (var i=0; i<aArray.length; i++) if (aArray[i] == oItem) return true;
return false;
}
function in_array_new(oItem, aArray)
{
for (var i in aArray) if (aArray[i] == oItem) return true;
return false;
}
var a = ['gab', '24', 'manila'];
var aArr1 = [1];
var b = {0:aArr1, 1:24, 2:'manila'};
var aArr2 = [1];
echo(in_array_orig(24, a)); // true
echo(in_array_new(24, b)); // true
echo(in_array_orig(aArr2, b)); // false
echo(in_array_new(aArr2, b)); // false
echo ((aArr1==aArr2)); // false
echo ((aArr1===aArr2)); // false
Thank you in advance for your assistance.