...

View Full Version : need to find index of object in multidimensional array



gloosemo
08-27-2011, 07:24 PM
I have an array "arr" that is an array of objects. Each object has the same 7 properties.

I want to find the index of the object with a property that matches a certain value x in the array arr. How can i accomplish this?

The array has hash tables associated with it.

arr [ obj [ i ] . property1 + "_" + obj [ i ] . property2 ] = arr [ i ] ;

so whats the index of the object where .property1 = x ?

Thanks, g

gloosemo
08-27-2011, 08:25 PM
sorry that should be


arr [ arr [ i ] . property1 + "_" + arr [ i ] . property2 ] = arr [ i ] ;

DaveyErwin
08-27-2011, 10:28 PM
<script>
var x = 12;
arr = new Array();
MyConstuctor = function(a){
this.property1 = a.shift();
this.property2 = a.shift();
this.property3 = a.shift();
this.property4 = a.shift();
this.property5 = a.shift();
this.property6 = a.shift();
this.property7 = a.shift();
}

arr[0] = new MyConstuctor([1,2,3,4,5,6,7]);
arr[1] = new MyConstuctor([8,9,10,11,12,13,14]);
arr[2] = new MyConstuctor([15,16,17,18,19,20,21]);


for(var i = arr.length;i--;)
for(var prop in arr[i])
if(arr[i][prop] == x)
alert("array arr index " + i +" contains an Object\n that has a property whose value is " + x)
</script>

I don't understand the part about the hash table ?

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum