# Associative array and indexOf question

**URL:** <https://forum.kirupa.com/t/associative-array-and-indexof-question/298182>\
**Category:** flash\
**Created:** [October 14, 2009, 8:29pm UTC](https://forum.kirupa.com/t/associative-array-and-indexof-question/298182 "2009-10-14T20:29:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![psych](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/psych/32/2839_2.png) [@psych](https://forum.kirupa.com/u/psych)\
**Post date:** [October 14, 2009, 8:29pm UTC](https://forum.kirupa.com/t/associative-array-and-indexof-question/298182/1 "2009-10-14T20:29:23Z")

</div>

Hi guys,

If i have an associative array like this for example:

```auto

var arr:Array = new Array();
arr.push({name:"John", last:"Doe"});
arr.push({name:"Jane", lase:"Doe"});

```

How can i get array index of elements whose name property is “John” for example without looping through every array element and checking like this:

```auto
for(var i:uint=0; i<arr.length; i++)
{
if (arr*["name"] == "John")
{
//do smth
}
}

```

I tried using indexOf which works with normal arrays but i guess not with associative array, i tried the following:

```auto
trace(arr.indexOf({name:"John"}));

```

But that didn’t work. Anyone has better idea? Can even indexOf() be used this way with associative arrays?

Thanks in advance,  
Best regards
