简体   繁体   中英

Search a value in Flex Array Collection

Is there a way to pass a value to a flex ArrayCollection and check whether it exists there or not. I mean, I want to insert values to a Flex Array but before that, i need to check if it already exists or not. Let me know if we can do this without looping through the ArrayCollection which i found as a bottleneck if the length of the ArrayCollection is high

Just check the API docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ArrayCollection.html

ArrayCollection#getItemIndex is what you want.

ArrayCollection has a "contains" method that you can use for this.

Note that if you really want to search fast, I would suggest that you create a lookup table or implement a binary search if your collection is always sorted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM