The role of the indexof of Array in Flex
1, the description
IndexOf used in the index from small to large lookup, if found on the return index value, can not find the return-1;
2. Example
(1) Design source
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"
Xmlns:s= "Library://ns.adobe.com/flex/spark"
xmlns:mx= "Library://ns.adobe.com/flex/mx"
Width= "100%" height= "100%" creationcomplete= "Creationhandler" (event) >
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<! [cdata[
Import mx.events.FlexEvent;
/**
* Initialization function
* IndexOf used to find from small to large in the index
* If you can find it, return the index value, and then return-1
*/
protected function Creationhandler (event:flexevent): void
{
var array:array = ["Peach tree", "Pear Tree", "Pine", "camphor Tree"];
if (Array.indexof ("Pear Tree")!=-1)
{
Trace ("By index from small to large check:" +array.indexof ("Pear Tree"));
}
if (Array.indexof ("Camphor Tree", 3)!=-1)
{
Trace ("Starting from the third element, by index from small to large check:" +array.indexof ("Camphor Tree", 3));
}
}
]]>
</fx:Script>
<fx:Declarations>
<!--place non-visual elements (such as services, value objects) here-->
</fx:Declarations>
</s:Application>
(2) Operation result
By index from small to large check: 1
Starting from the third element, by index from small to large: 3