how do I find an object's index in an array
Hi,
I've got this code that is looking for the closest number to 0 in my array :
var tideArray = new Array();
tideArray.push({tide:"haute", difference: "-14"});
tideArray.push({tide:"haute", difference: "3"});
tideArray.push({tide:"basse", difference: "-4"});
tideArray.push({tide:"basse", difference: "8"});
if (tideArray.length > 0)
{
var minItem: Object = tideArray[0];
for (var index:int = 1; index < tideArray.length; index++)
{
if (Math.abs(tideArray[index].difference) < Math.abs(minItem.difference))
{
minItem = tideArray[index];
}
}}
trace(minItem.difference) // OUTPUT is 3 in this case
Is there a way to find the index of minItem.difference in my tideArray ? (so, the result here should be index = 1 )
I've tried tideArray.indexOf(minItem.difference) but the output is -1, so the index wasn't found...
