Functions of array indexof In Flex
1. Description
Indexof is used to search for indexes from small to large. If the index value is queried,-1 is returned if the index value is not found;
2. Instance
(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;/*** initialization function * indexof is used to search for indexes from small to large. * if it is obtained, the index value is returned, -1 */protected function creationhandler (Event: flexevent): void {var array: array = ["Peach Tree", "Pear Tree", "Pine Tree ", "camphor tree"]; If (array. indexof ("Lishu ")! =-1) {trace ("query by index from small to large:" + array. indexof ("Lishu");} If (array. indexof ("camphor tree", 3 )! =-1) {trace ("starting from the third element, querying by index from small to large:" + array. indexof ("camphor tree", 3) ;}]]> </FX: SCRIPT> <FX: declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </FX: declarations> </S: Application>
(2) execution result
Query by index from small to large: 1
Starting from the third element, query by index from small to large: 3
Functions of array indexof In Flex