Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 944933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:40:26+00:00 2026-05-15T22:40:26+00:00

Is there an XMLList equivalent to Array.indexOf? For example – var array:Array = [‘one’,’two’];

  • 0

Is there an XMLList equivalent to Array.indexOf?

For example –

var array:Array = ['one','two'];
trace(array.indexOf('two')); // returns 1, since it's at the second position
trace(array.indexOf('three')); // returns -1, since it isn't found

… right? but what if I’ve got this –

var xml:XML = <list><item>one</item><item>two</item><list>
var xmlList:XMLList = list.item;

there’s got to be an easier way to check to see if one of the nodes in the XMLList has a particular value than looping through all of them, right? something akin to –

xmlList.indexOfChildByNodeValue('two'); // returns 1, because it's the second child
xmlList.indexOfChildByNodeValue('three'); // returns -1, because it doesn't match any children

make sense?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:40:26+00:00Added an answer on May 15, 2026 at 10:40 pm

    I put together a demo of how you can do it without looping. Though it does call for a little more upfront work. Though it pays off if you are going to be checking values a lot.

    <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" minWidth="955" minHeight="600" applicationComplete="_init();">
        <fx:Declarations>
            <fx:XML id="movieList" source="http://www.movies.com/rss-feeds/jen-yamato-reviews-rss" />
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.logging.ILogger;
                import mx.logging.Log;
                import mx.logging.LogEventLevel;
                import mx.logging.targets.TraceTarget;
    
                public static const MOVIE_TITLE:String = "Inception";
    
                private var _logger:ILogger = Log.getLogger("Sandbox");
    
                private function _init() :void
                {
                    var traceTarget:TraceTarget = new TraceTarget();
                    traceTarget.level = LogEventLevel.ALL;
                    Log.addTarget(traceTarget);
    
                    var xmlList:XMLList = movieList..item;
    
                    var firstItem:XML = movieList..item[0];
                    var firstItemIndex:int = firstItem.childIndex();
                    _logger.info("First Item Index: " + firstItemIndex);
    
                    var item:XML = xmlList.(title == MOVIE_TITLE)[0];
                    _logger.info("Contains: " + xmlList.contains(item) + " // " + item.childIndex());
    
                    var actualIndex:int = (item.childIndex() - firstItemIndex);
                    _logger.info("Actual Index: " + actualIndex);
    
                    _logger.info("Result: " + xmlList[actualIndex]);
                }
            ]]>
        </fx:Script>
    
    </s:Application>
    

    The basic idea is that you store the index of the first item and then subtract that from the childIndex() of the matched result using E4X search.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two table s : one is the master and one the detail
There is an XMLList of items, each item has three properties: prop1, prop2, and
There are two intents on the receiver side which are called from the same
There are several shading languages available today like GLSL, HLSL, CG, which one to
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There are some stdlib functions that throw errors on invalid input. For example: Prelude>
There are two major fix engines: opensource QuickFix http://www.quickfixengine.org/ commercial Fix Antenna http://www.b2bits.com/trading_solutions/fix_engines/fix_engine_cpp.html What
There is something strange happening. Param interceptor is the one in charge to take
There are one check box and a non editable text box corresponding to it.
Basically, since XMLList are similar to Arrays in many ways, I was wondering if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.