用户登录
用户注册

分享至

Flex中Array的IndexOf 的作用示例介绍

  • 作者: 亲别动_屎里有毒
  • 来源: 51数据库
  • 2021-07-03

flex中 array 的indexof 的作用

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

软件
前端设计
程序设计
Java相关