Example introduction to the role of IndexOf of Array in Flex
The role of IndexOf of Array in Flex
1. Description
indexOf is used to search from small to large in the index. If it can be found, it will return the index value. If it cannot be found, it will return - 1;
2. Example
(1) Design source code
<?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) Running result
Press Search the index from small to large: 1
Start from the third element, search by index from small to large: 3
For more examples of the role of IndexOf of Array in Flex, please pay attention to the PHP Chinese website for related articles!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

