• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

indexOf on multidimensional array

Contributor ,
May 11, 2013 May 11, 2013

Copy link to clipboard

Copied

var clipArray:Array = new Array();

clipArray[0] = new Array();

clipArray[1] = new Array();

clipArray[0][0]=2

clipArray[0][1]=3

clipArray[1][0]=4

clipArray[1][1]=5

trace(clipArray[0].indexOf(3));

This traces '1' cause 3 can be found in [0][1] of the multidimensional array and 1 is the second value of that 0.

Using indexOf this way I can determine that second value in which in this case the value 3 can be found.

I want to to take this one step further and use indexOf somehow to determine the first value of the clipArray variable. So looking for 2 or 3 should trace 0 and looking for 4 or 5 should trace 1. Is there some way to do this?

TOPICS
ActionScript

Views

333

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2013 May 11, 2013

Copy link to clipboard

Copied

LATEST

the following returns both indices:

function indexOf2D(a:Array,v:*):Array{

for(var i:int=0;i<a.length;i++){

for(var j:int=0;j<a.length;j++){

if(a==v){

return [i,j];

}

}

}

return [-1,-1];

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines