1、说明
indexOf用于在索引中从小到大查找,如果查得到就返回索引值,查不到就返回-1;
2、实例
(1)设计源码
复制代码 代码如下:
<?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;
/**
* 初始化函数
* indexOf用于在索引中从小到大查找
* 如果查得到就返回索引值,查不到就返回-1
*/
protected function creationHandler(event:FlexEvent):void
{
var array:Array = [\”桃树\”,\”梨树\”,\”松树\”,\”樟树\”];
if(array.indexOf(\”梨树\”) != -1)
{
trace(\”按索引从小到大查:\”+array.indexOf(\”梨树\”));
}
if(array.indexOf(\”樟树\”,3) != -1)
{
trace(\”从第三个元素开始,按索引从小到大查:\”+array.indexOf(\”樟树\”,3));
}
}
]]>
</fx:Script>
<fx:Declarations>
<!– 将非可视元素(例如服务、值对象)放在此处 –>
</fx:Declarations>
</s:Application>
(2)运行结果
按索引从小到大查:1
从第三个元素开始,按索引从小到大查:3